forked from atomic-coders/react-native-wkwebview
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAQWebView.ios.js
More file actions
88 lines (76 loc) · 2.24 KB
/
AQWebView.ios.js
File metadata and controls
88 lines (76 loc) · 2.24 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
var React = require('react');
var {
PropTypes,
} = React;
var ReactNative = require('react-native');
var {
requireNativeComponent,
NativeModules
} = ReactNative;
var AQWebView = requireNativeComponent('AQWebView', WKWebView);
class WKWebView extends React.Component {
goBack() {
NativeModules.AQWebViewManager.goBack(React.findNodeHandle(this.refs.AQWebView));
}
goForward() {
NativeModules.AQWebViewManager.goForward(React.findNodeHandle(this.refs.AQWebView));
}
getNavigationState(callback) {
NativeModules.AQWebViewManager.baseEvent(React.findNodeHandle(this.refs.AQWebView), (err, res) => {
if (err) {
callback('Getting navigation state from webview error: ' + err)
}
else {
callback(null, res)
}
})
}
_onLoadingStart(navState) {
if (this.props.onNavigationStateChange) {
this.props.onNavigationStateChange({type: 'start', ...navState.nativeEvent});
}
}
_onLoadingEnd(navState) {
if (this.props.onNavigationStateChange) {
this.props.onNavigationStateChange({type: 'end', ...navState.nativeEvent});
}
}
_onLoadingError(navState) {
if (this.props.onNavigationStateChange) {
this.props.onNavigationStateChange({type: 'error', ...navState.nativeEvent});
}
}
render() {
return <AQWebView ref="AQWebView"
{...this.props}
onLoadingStart={this._onLoadingStart.bind(this)}
onLoadingFinish={this._onLoadingEnd.bind(this)}
onLoadingError={this._onLoadingError.bind(this)}
/>;
}
}
WKWebView.propTypes = {
source: PropTypes.oneOfType([
PropTypes.shape({
uri: PropTypes.string,
method: PropTypes.string,
headers: PropTypes.object,
body: PropTypes.string
}),
PropTypes.shape({
html: PropTypes.string,
baseUrl: PropTypes.string
})
]),
onNavigationStateChange: PropTypes.func,
automaticallyAdjustContentInsets: PropTypes.bool,
contentInset: PropTypes.shape({
top: PropTypes.number,
left: PropTypes.number,
bottom: PropTypes.number,
right: PropTypes.number
}),
blockedPrefixes: PropTypes.arrayOf(PropTypes.string),
onPrefixBlocked: PropTypes.func
};
module.exports = WKWebView;