File tree Expand file tree Collapse file tree 1 file changed +12
-7
lines changed Expand file tree Collapse file tree 1 file changed +12
-7
lines changed Original file line number Diff line number Diff line change @@ -19,22 +19,27 @@ const injectScript = `
19
19
if (WebViewBridge) {
20
20
21
21
WebViewBridge.onMessage = function (message) {
22
- alert(message);
22
+ if (message === "hello from react-native") {
23
+ WebViewBridge.send("got the message inside webview");
24
+ }
23
25
};
24
26
25
27
WebViewBridge.send("hello from webview");
26
-
27
- } else {
28
- window.location.href = "yahoo.ca";
29
28
}
30
29
}());
31
30
` ;
32
31
33
32
var Sample2 = React . createClass ( {
34
33
onBridgeMessage : function ( message ) {
35
- if ( message == "hello from webview" ) {
36
- console . log ( message ) ;
37
- this . refs . webviewbridge . sendToBridge ( "hello from react-native" ) ;
34
+ const { webviewbridge } = this . refs ;
35
+
36
+ switch ( message ) {
37
+ case "hello from webview" :
38
+ webviewbridge . sendToBridge ( "hello from react-native" ) ;
39
+ break ;
40
+ case "got the message inside webview" :
41
+ console . log ( "we have got a message from webview! yeah" ) ;
42
+ break ;
38
43
}
39
44
} ,
40
45
render : function ( ) {
You can’t perform that action at this time.
0 commit comments