forked from jordaaash/react-native-webview-crosswalk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.android.js
More file actions
94 lines (87 loc) · 2.82 KB
/
index.android.js
File metadata and controls
94 lines (87 loc) · 2.82 KB
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
'use strict';
import React, { PropTypes } from 'react';
import ReactNative, { requireNativeComponent, View } from 'react-native';
var {
addons: { PureRenderMixin },
NativeModules: { UIManager, CrosswalkWebViewManager: { JSNavigationScheme } }
} = ReactNative;
var resolveAssetSource = require('react-native/Libraries/Image/resolveAssetSource');
var WEBVIEW_REF = 'crosswalkWebView';
var CrosswalkWebView = React.createClass({
mixins: [PureRenderMixin],
statics: { JSNavigationScheme },
propTypes: {
injectedJavaScript: PropTypes.string,
localhost: PropTypes.bool.isRequired,
onError: PropTypes.func,
onNavigationStateChange: PropTypes.func,
source: PropTypes.oneOfType([
PropTypes.shape({
uri: PropTypes.string, // URI to load in WebView
}),
PropTypes.shape({
html: PropTypes.string, // static HTML to load in WebView
}),
PropTypes.number, // used internally by React packager
]),
url: PropTypes.string,
...View.propTypes
},
getDefaultProps () {
return {
localhost: false
};
},
render () {
var source = this.props.source || {};
if (this.props.url) {
source.uri = this.props.url;
}
return (
<NativeCrosswalkWebView
{ ...this.props }
onError={ this.onError }
onNavigationStateChange={ this.onNavigationStateChange }
ref={ WEBVIEW_REF }
source={ resolveAssetSource(source) }/>
);
},
getWebViewHandle () {
return ReactNative.findNodeHandle(this.refs[WEBVIEW_REF]);
},
onNavigationStateChange (event) {
var { onNavigationStateChange } = this.props;
if (onNavigationStateChange) {
onNavigationStateChange(event.nativeEvent);
}
},
onError (event) {
var { onError } = this.props;
if (onError) {
onError(event.nativeEvent);
}
},
goBack () {
UIManager.dispatchViewManagerCommand(
this.getWebViewHandle(),
UIManager.CrosswalkWebView.Commands.goBack,
null
);
},
goForward () {
UIManager.dispatchViewManagerCommand(
this.getWebViewHandle(),
UIManager.CrosswalkWebView.Commands.goForward,
null
);
},
reload () {
UIManager.dispatchViewManagerCommand(
this.getWebViewHandle(),
UIManager.CrosswalkWebView.Commands.reload,
null
);
}
});
var NativeCrosswalkWebView = requireNativeComponent('CrosswalkWebView', CrosswalkWebView);
export default CrosswalkWebView;