Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 9 additions & 8 deletions WKWebView.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ type ErrorEvent = {

type Event = Object;

const defaultRenderLoading = () => (
<View style={styles.loadingView}>
<ActivityIndicator />
const defaultRenderLoading = (loadingStyle, loadingSize) => (
<View style={[styles.loadingView, loadingStyle]}>
<ActivityIndicator size={loadingSize || null} />
</View>
);
const defaultRenderError = (errorDomain, errorCode, errorDesc) => (
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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];
Expand Down Expand Up @@ -372,7 +373,7 @@ class WKWebView extends React.Component {
/>;

return (
<View style={styles.container}>
<View style={[styles.container, this.props.containerStyle]}>
{webView}
{otherView}
</View>
Expand Down
19 changes: 13 additions & 6 deletions ios/RCTWKWebView/RCTWKWebView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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<NSString *, id> *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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}