mirror of
https://github.com/status-im/react-native-webview-bridge.git
synced 2026-08-30 21:01:12 +00:00
got 2 ways to work
This commit is contained in:
@@ -18,8 +18,8 @@ const injectScript = `
|
||||
(function () {
|
||||
if (window.WebViewBridge) {
|
||||
|
||||
WebViewBridge.addMessageListener(function (message) {
|
||||
alert(message)
|
||||
WebViewBridge.addMessageListener(function (payload) {
|
||||
alert(payload.message)
|
||||
});
|
||||
|
||||
WebViewBridge.send({ message: 'This is working' });
|
||||
@@ -29,12 +29,16 @@ const injectScript = `
|
||||
|
||||
class rpc extends Component {
|
||||
onMessage = (payload) => {
|
||||
console.log(payload.message)
|
||||
if (this.bridgeRef) {
|
||||
console.log(payload.message)
|
||||
this.bridgeRef.sendToBridge({ message: 'This is working too' })
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
console.log(injectScript)
|
||||
return (
|
||||
<WebView
|
||||
ref={(ref) => this.bridgeRef = ref}
|
||||
source={{uri: 'https://github.com/facebook/react-native'}}
|
||||
style={{marginTop: 20}}
|
||||
javaScriptEnabled={true}
|
||||
|
||||
@@ -24,7 +24,8 @@ import {
|
||||
View,
|
||||
ScrollView,
|
||||
NativeModules,
|
||||
requireNativeComponent
|
||||
requireNativeComponent,
|
||||
findNodeHandle
|
||||
} from 'react-native'
|
||||
|
||||
import invariant from 'fbjs/lib/invariant'
|
||||
@@ -495,7 +496,7 @@ class WebView extends React.Component {
|
||||
* Returns the native `WebView` node.
|
||||
*/
|
||||
getWebViewHandle = (): any => {
|
||||
return ReactNative.findNodeHandle(this.refs[RCT_WEBVIEW_REF]);
|
||||
return findNodeHandle(this.refs[RCT_WEBVIEW_REF]);
|
||||
};
|
||||
|
||||
_onLoadingStart = (event: Event) => {
|
||||
|
||||
Reference in New Issue
Block a user