File tree Expand file tree Collapse file tree 3 files changed +57
-86
lines changed Expand file tree Collapse file tree 3 files changed +57
-86
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * Sample React Native App
3
+ * https://github.com/facebook/react-native
4
+ */
5
+ 'use strict' ;
6
+
7
+ var React = require ( 'react-native' ) ;
8
+ var {
9
+ StyleSheet,
10
+ Text,
11
+ View,
12
+ } = React ;
13
+
14
+ var WebViewBridge = require ( 'react-native-webview-bridge' ) ;
15
+
16
+ const injectScript = `
17
+ (function () {
18
+ if (WebViewBridge) {
19
+
20
+ WebViewBridge.onMessage = function (message) {
21
+ alert('got a message from Native: ' + message);
22
+
23
+ WebViewBridge.send("message from webview");
24
+ };
25
+
26
+ }
27
+ }());
28
+ ` ;
29
+
30
+ var Sample2 = React . createClass ( {
31
+ componentDidMount ( ) {
32
+ setTimeout ( ( ) => {
33
+ this . refs . webviewbridge . sendToBridge ( "hahaha" ) ;
34
+ } , 5000 ) ;
35
+ } ,
36
+ onBridgeMessage : function ( message ) {
37
+ console . log ( message ) ;
38
+ } ,
39
+ render : function ( ) {
40
+ return (
41
+ < WebViewBridge
42
+ ref = "webviewbridge"
43
+ onBridgeMessage = { this . onBridgeMessage }
44
+ injectedJavaScript = { injectScript }
45
+ onBridgeMessage = { ( message ) => {
46
+ console . log ( message ) ;
47
+ } }
48
+ url = { "http://google.com" } />
49
+ ) ;
50
+ }
51
+ } ) ;
52
+
53
+ module . exports = Sample2 ;
Original file line number Diff line number Diff line change 5
5
'use strict' ;
6
6
7
7
var React = require ( 'react-native' ) ;
8
- var {
9
- AppRegistry,
10
- StyleSheet,
11
- Text,
12
- View,
13
- } = React ;
8
+ var { AppRegistry } = React ;
14
9
15
- var Sample2 = React . createClass ( {
16
- render : function ( ) {
17
- return (
18
- < View style = { styles . container } >
19
- < Text style = { styles . welcome } >
20
- Welcome to React Native!
21
- </ Text >
22
- < Text style = { styles . instructions } >
23
- To get started, edit index.android.js
24
- </ Text >
25
- < Text style = { styles . instructions } >
26
- Shake or press menu button for dev menu
27
- </ Text >
28
- </ View >
29
- ) ;
30
- }
31
- } ) ;
32
-
33
- var styles = StyleSheet . create ( {
34
- container : {
35
- flex : 1 ,
36
- justifyContent : 'center' ,
37
- alignItems : 'center' ,
38
- backgroundColor : '#F5FCFF' ,
39
- } ,
40
- welcome : {
41
- fontSize : 20 ,
42
- textAlign : 'center' ,
43
- margin : 10 ,
44
- } ,
45
- instructions : {
46
- textAlign : 'center' ,
47
- color : '#333333' ,
48
- marginBottom : 5 ,
49
- } ,
50
- } ) ;
10
+ var Sample2 = require ( './app' ) ;
51
11
52
12
AppRegistry . registerComponent ( 'Sample2' , ( ) => Sample2 ) ;
Original file line number Diff line number Diff line change 5
5
'use strict' ;
6
6
7
7
var React = require ( 'react-native' ) ;
8
- var {
9
- AppRegistry,
10
- StyleSheet,
11
- Text,
12
- View,
13
- } = React ;
8
+ var { AppRegistry } = React ;
14
9
15
- var WebViewBridge = require ( 'react-native-webview-bridge' ) ;
16
-
17
- const injectScript = `
18
- (function () {
19
- if (WebViewBridge) {
20
-
21
- WebViewBridge.onMessage = function (message) {
22
- alert('got a message from Native: ' + message);
23
-
24
- WebViewBridge.send("message from webview");
25
- };
26
-
27
- }
28
- }());
29
- ` ;
30
-
31
- var Sample2 = React . createClass ( {
32
- componentDidMount ( ) {
33
- setTimeout ( ( ) => {
34
- this . refs . webviewbridge . sendToBridge ( "hahaha" ) ;
35
- } , 5000 ) ;
36
- } ,
37
- onBridgeMessage : function ( message ) {
38
- console . log ( message ) ;
39
- } ,
40
- render : function ( ) {
41
- return (
42
- < WebViewBridge
43
- ref = "webviewbridge"
44
- onBridgeMessage = { this . onBridgeMessage }
45
- injectedJavaScript = { injectScript }
46
- onBridgeMessage = { ( message ) => {
47
- console . log ( message ) ;
48
- } }
49
- url = { "http://google.com" } />
50
- ) ;
51
- }
52
- } ) ;
10
+ var Sample2 = require ( './app' ) ;
53
11
54
12
AppRegistry . registerComponent ( 'Sample2' , ( ) => Sample2 ) ;
You can’t perform that action at this time.
0 commit comments