forked from lucasferreira/react-native-webview-android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.android.js
90 lines (84 loc) · 2.5 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
/**
* @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
},
_onNavigationStateChange: function(event) {
if (this.props.onNavigationStateChange) {
this.props.onNavigationStateChange(event.nativeEvent);
}
},
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} />;
},
_getWebViewHandle: function() {
return RN.findNodeHandle(this.refs[WEBVIEW_REF]);
},
});
var RNWebViewAndroid = requireNativeComponent('RNWebViewAndroid', null);
module.exports = WebViewAndroid;