Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Communication between React Native and WebView's content #9

Closed
pfeiffer opened this issue Aug 17, 2022 · 0 comments · Fixed by #11
Closed

Communication between React Native and WebView's content #9

pfeiffer opened this issue Aug 17, 2022 · 0 comments · Fixed by #11

Comments

@pfeiffer
Copy link
Contributor

pfeiffer commented Aug 17, 2022

Turbo iOS and Turbo Android supports communication between native app and JavaScript (the visited page). This is very useful for eg. programatically doing something natively, triggered from the website or for programatically doing something on the website, triggered natively.

Examples of this could be prompting for Push Permissions and upon acceptance returning the push token back to the visited website, or reloading the web page when a native push notification is received.

It would be very useful to be able to register a handler for messages being passed from the website to native, eg:

// In React Native
<VisitableView onMessage={alert} />

// In website:
website.messageHandlers["someName"].postMessage("Hi from website!")

And vice-versa being able to send messages back to the web page:

// In React Native
visitableViewRef.injectJavaScript("alert('Hello from native!');")

Simply having these low-level methods of passing data back and forth and could be extended with eg. JSON serialization, async callbacks etc. with a bit of JS code on React Native side and website.

Prior art:

react-native-webview: https://github.com/react-native-webview/react-native-webview/blob/master/docs/Guide.md#communicating-between-js-and-native
turbo-ios: https://github.com/hotwired/turbo-ios/blob/main/Docs/Advanced.md#native---javascript-integration
turbo-android: https://github.com/hotwired/turbo-android/blob/main/docs/ADVANCED-OPTIONS.md#native---javascript-integration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant