react-native-webviewhook
React Native WebView with client-side hook (iOS + Android)
Why?
Sometimes you need to be able to callback to your react-native app from a web page. The solutions that currently exist for this are either broken on one of the platforms, bloated with features you don't need, or in the case of implementing this directly into the WebView component – delayed for numerous reasons.
I needed a simple WebView which allowed me to pass a string back to react-native via a hook.
This is that component.
Install
npm i react-native-webviewhook --save
Usage
Place this in your index.ios.js
and/or index.android.js
:
{ superprops this } { return <View style= flex: 1 paddingTop: 22 > <WebViewHook onHookMessage=this_onHookMessage source=uri: 'http://localhost:4000/' /> </View> } { this_onHookMessage = this_onHookMessage } { console } AppRegistry
On the web page you load (http://localhost:4000/
for me), send text back to RN with the hook(<string>)
function:
Test