forked from gmfe/react-native-gm-webview
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.android.js
118 lines (110 loc) · 3.21 KB
/
index.android.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/**
* @providesModule WebViewAndroid
*/
"use strict";
var React = require("react");
var RN = require("react-native");
var createClass = require("create-react-class");
var PropTypes = require("prop-types");
var { requireNativeComponent, NativeModules } = require("react-native");
var RCTUIManager = NativeModules.UIManager;
var WEBVIEW_REF = "androidWebView";
var WebViewAndroid = createClass({
propTypes: {
url: PropTypes.string,
source: PropTypes.object,
baseUrl: PropTypes.string,
html: PropTypes.string,
htmlCharset: PropTypes.string,
userAgent: PropTypes.string,
injectedJavaScript: PropTypes.string,
disablePlugins: PropTypes.bool,
disableCookies: PropTypes.bool,
javaScriptEnabled: PropTypes.bool,
geolocationEnabled: PropTypes.bool,
allowUrlRedirect: PropTypes.bool,
builtInZoomControls: PropTypes.bool,
onNavigationStateChange: PropTypes.func,
onMessage: PropTypes.func,
onShouldStartLoadWithRequest: PropTypes.func,
},
_onNavigationStateChange: function(event) {
if (this.props.onNavigationStateChange) {
this.props.onNavigationStateChange(event);
}
},
_onMessage: function(event) {
if (this.props.onMessage) {
this.props.onMessage(event);
}
},
_onShouldOverrideUrlLoading: function(event) {
let shouldOverride = false;
if (this.props.onShouldStartLoadWithRequest) {
shouldOverride = !this.props.onShouldStartLoadWithRequest(event);
}
RCTUIManager.dispatchViewManagerCommand(
this._getWebViewHandle(),
RCTUIManager.RNWebViewAndroid.Commands.shouldOverrideWithResult,
[shouldOverride]
);
},
goBack: function() {
RCTUIManager.dispatchViewManagerCommand(
this._getWebViewHandle(),
RCTUIManager.RNWebViewAndroid.Commands.goBack,
null
);
},
goForward: function() {
RCTUIManager.dispatchViewManagerCommand(
this._getWebViewHandle(),
RCTUIManager.RNWebViewAndroid.Commands.goForward,
null
);
},
reload: function() {
RCTUIManager.dispatchViewManagerCommand(
this._getWebViewHandle(),
RCTUIManager.RNWebViewAndroid.Commands.reload,
null
);
},
stopLoading: function() {
RCTUIManager.dispatchViewManagerCommand(
this._getWebViewHandle(),
RCTUIManager.RNWebViewAndroid.Commands.stopLoading,
null
);
},
postMessage: function(data) {
RCTUIManager.dispatchViewManagerCommand(
this._getWebViewHandle(),
RCTUIManager.RNWebViewAndroid.Commands.postMessage,
[String(data)]
);
},
injectJavaScript: function(data) {
RCTUIManager.dispatchViewManagerCommand(
this._getWebViewHandle(),
RCTUIManager.RNWebViewAndroid.Commands.injectJavaScript,
[data]
);
},
render: function() {
return (
<RNWebViewAndroid
ref={WEBVIEW_REF}
{...this.props}
onNavigationStateChange={this._onNavigationStateChange}
onMessageEvent={this._onMessage}
onShouldOverrideUrlLoading={this._onShouldOverrideUrlLoading}
/>
);
},
_getWebViewHandle: function() {
return RN.findNodeHandle(this.refs[WEBVIEW_REF]);
},
});
var RNWebViewAndroid = requireNativeComponent("RNWebViewAndroid", null);
module.exports = WebViewAndroid;