From 61161d948843ddc40e6c2a151c142aa60c186c3c Mon Sep 17 00:00:00 2001 From: inokawa <48897392+inokawa@users.noreply.github.com> Date: Sat, 11 May 2024 17:20:25 +0900 Subject: [PATCH] Change useWebViewMessage and emit API --- README.md | 20 +++++++------- ...smoke-webview-with-json-jsx-1-chromium.txt | 10 +++---- examples/DempApp/WebApp/index.jsx | 4 +-- examples/DempApp/app/(tabs)/index.tsx | 9 ++++--- src/index.ts | 2 +- src/native/index.ts | 26 ++++++++++--------- src/web/core.ts | 2 +- src/web/preact.ts | 8 ++++-- src/web/react.spec.tsx | 6 ++--- src/web/react.ts | 8 ++++-- 10 files changed, 53 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index 954b1205..36c0385d 100644 --- a/README.md +++ b/README.md @@ -25,9 +25,8 @@ The communication between React app and React Native app will be also simplified - All JS modules (with or without JSX/TypeScript) will be bundled with [esbuild](https://github.com/evanw/esbuild). - **NOTE: Only the edits in the entry file of web will invoke rebuild because of the limitation of [metro](https://github.com/facebook/metro)'s build process.** - Handle communication between React Native and WebView with React hook style - - With `useWebViewMessage` hook, you can subscribe messages from WebView. - - With `useNativeMessage` hook, you can subscribe messages from React Native. - - `emit` function sends message. + - With `useWebViewMessage` hook, you can subscribe messages from WebView sent with `emitToWebView`. + - With `useNativeMessage` hook, you can subscribe messages from React Native sent with `emitToNative`. - Support bundling some assets in web side with [ES6 import syntax](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) - `.json` is imported as an object, like require in Node.js. - `.txt` and `.md` are imported as string, like [raw-loader](https://github.com/webpack-contrib/raw-loader). @@ -157,7 +156,7 @@ module.exports = (async () => { import React, { useState } from "react"; import { webViewRender, - emit, + emitToNative, useNativeMessage, } from "react-native-react-bridge/lib/web"; // Importing css is supported @@ -179,10 +178,10 @@ const Root = () => {