diff --git a/README.md b/README.md index 14435f87..263d6d57 100644 --- a/README.md +++ b/README.md @@ -129,6 +129,9 @@ Enable horizontal swipe gestures will trigger back-forward navigations. Derived - source - startInLoadingState - style +- containerStyle (optional) +- loadingStyle (optional) +- loadingSize (optional) - url (deprecated) - bounces - onShouldStartLoadWithRequest diff --git a/WKWebView.ios.js b/WKWebView.ios.js index a24024a2..9056a5ca 100644 --- a/WKWebView.ios.js +++ b/WKWebView.ios.js @@ -47,9 +47,9 @@ type ErrorEvent = { type Event = Object; -const defaultRenderLoading = () => ( - - +const defaultRenderLoading = (loadingStyle, loadingSize) => ( + + ); const defaultRenderError = (errorDomain, errorCode, errorDesc) => ( @@ -203,6 +203,9 @@ class WKWebView extends React.Component { scalesPageToFit: PropTypes.bool, startInLoadingState: PropTypes.bool, style: ViewPropTypes.style, + containerStyle: ViewPropTypes.style, + loadingStyle: ViewPropTypes.style, + loadingSize: null | "small" | "large", /** * If false injectJavaScript will run both main frame and iframe * @platform ios @@ -290,7 +293,7 @@ class WKWebView extends React.Component { let otherView = null; if (this.state.viewState === WebViewState.LOADING) { - otherView = (this.props.renderLoading || defaultRenderLoading)(); + otherView = (this.props.renderLoading || defaultRenderLoading)(this.props.loadingStyle, this.props.loadingSize); } else if (this.state.viewState === WebViewState.ERROR) { const errorEvent = this.state.lastErrorEvent; invariant( @@ -303,9 +306,7 @@ class WKWebView extends React.Component { errorEvent.description ); } else if (this.state.viewState !== WebViewState.IDLE) { - console.error( - 'CRAWKWebView invalid state encountered: ' + this.state.loading - ); + console.error('CRAWKWebView invalid state encountered: ' + this.state.loading); } const webViewStyles = [styles.container, styles.webView, this.props.style]; @@ -372,7 +373,7 @@ class WKWebView extends React.Component { />; return ( - + {webView} {otherView} diff --git a/ios/RCTWKWebView/RCTWKWebView.m b/ios/RCTWKWebView/RCTWKWebView.m index 3c9eb7a5..6cc1d423 100644 --- a/ios/RCTWKWebView/RCTWKWebView.m +++ b/ios/RCTWKWebView/RCTWKWebView.m @@ -614,20 +614,27 @@ - (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNaviga NSDictionary *headers = @{}; NSInteger statusCode = 200; if([navigationResponse.response isKindOfClass:[NSHTTPURLResponse class]]){ - headers = ((NSHTTPURLResponse *)navigationResponse.response).allHeaderFields; - statusCode = ((NSHTTPURLResponse *)navigationResponse.response).statusCode; + headers = ((NSHTTPURLResponse *)navigationResponse.response).allHeaderFields; + statusCode = ((NSHTTPURLResponse *)navigationResponse.response).statusCode; } - + NSMutableDictionary *event = [self baseEvent]; [event addEntriesFromDictionary:@{ @"headers": headers, @"status": [NSHTTPURLResponse localizedStringForStatusCode:statusCode], @"statusCode": @(statusCode), }]; - _onNavigationResponse(event); + // check status code + if(statusCode == 200) { + _onNavigationResponse(event); + decisionHandler(WKNavigationResponsePolicyAllow); + } else { + RCTLogWarn(@"Something wrong, statusCode is %zd!", statusCode); + decisionHandler(WKNavigationResponsePolicyCancel); + } + } else { + decisionHandler(WKNavigationResponsePolicyAllow); } - - decisionHandler(WKNavigationResponsePolicyAllow); } @end diff --git a/package.json b/package.json index 5505776b..50ed61f5 100644 --- a/package.json +++ b/package.json @@ -77,5 +77,5 @@ "sync-from-example": "cp ./example/node_modules/react-native-wkwebview-reborn/*.js ./;cp -r ./example/node_modules/react-native-wkwebview-reborn/ios ./", "sync-to-example": "cp ./*.js ./example/node_modules/react-native-wkwebview-reborn/;cp -r ./ios ./example/node_modules/react-native-wkwebview-reborn/" }, - "version": "1.22.0" + "version": "1.23.0" }