got 2 ways to work

This commit is contained in:
Ali Najafizadeh
2016-09-27 13:22:19 -04:00
parent 352863c0fb
commit 05188ac40d
2 changed files with 11 additions and 6 deletions
+8 -4
View File
@@ -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}
+3 -2
View File
@@ -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) => {