Skip to content

Commit ebb9bdb

Browse files
committed
Added more methods to React component
1 parent 1b64073 commit ebb9bdb

1 file changed

Lines changed: 25 additions & 11 deletions

File tree

AQWebView.ios.js

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,45 @@
11
var React = require('react-native');
22
var {
33
requireNativeComponent,
4-
PropTypes
4+
PropTypes,
5+
NativeModules
56
} = React;
67

78
class WKWebView extends React.Component {
89

910
goBack() {
10-
this.refs.AQWebView.goBack();
11+
NativeModules.AQWebViewManager.goBack(React.findNodeHandle(this.refs.AQWebView);
1112
}
1213

1314
goForward() {
14-
this.refs.AQWebView.goForward();
15+
NativeModules.AQWebViewManager.goForward(React.findNodeHandle(this.refs.AQWebView);
1516
}
1617

17-
canGoForward() {
18-
this.refs.AQWebView.canGoForward();
18+
_onLoadingStart(navState) {
19+
if (this.props.onNavigationStateChange) {
20+
this.props.onNavigationStateChange({type: 'start', ...navState.nativeEvent});
21+
}
1922
}
2023

21-
canGoBack() {
22-
this.refs.AQWebView.canGoBack();
24+
_onLoadingEnd(navState) {
25+
if (this.props.onNavigationStateChange) {
26+
this.props.onNavigationStateChange({type: 'end', ...navState.nativeEvent});
27+
}
28+
}
29+
30+
_onLoadingError(navState) {
31+
if (this.props.onNavigationStateChange) {
32+
this.props.onNavigationStateChange({type: 'error', ...navState.nativeEvent});
33+
}
2334
}
2435

2536
render() {
26-
return <AQWebView ref="AQWebView" {...this.props} />;
37+
return <AQWebView ref="AQWebView"
38+
{...this.props}
39+
onLoadingStart={this._onLoadingStart.bind(this)}
40+
onLoadingEnd={this._onLoadingEnd.bind(this)}
41+
onLoadingError={this._onLoadingError.bind(this)}
42+
/>;
2743
}
2844

2945
}
@@ -42,9 +58,7 @@ WKWebView.propTypes = {
4258
}),
4359
]),
4460

45-
onLoadingStart: PropTypes.func,
46-
onLoadingFinish: PropTypes.func,
47-
onLoadingError: PropTypes.func,
61+
onNavigationStateChange: PropTypes.func,
4862

4963
automaticallyAdjustContentInsets: PropTypes.bool,
5064
contentInset: PropTypes.shape({

0 commit comments

Comments
 (0)