Skip to content

Commit 8a11f80

Browse files
committed
refactor: make reusable allowNavigation block
1 parent adfe5ff commit 8a11f80

1 file changed

Lines changed: 16 additions & 13 deletions

File tree

apple/RNCWebView.m

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,6 +1106,21 @@ - (void) webView:(WKWebView *)webView
11061106
NSURLRequest *request = navigationAction.request;
11071107
BOOL isTopFrame = [request.URL isEqual:request.mainDocumentURL];
11081108

1109+
void (^allowNavigation)(void) = ^{
1110+
if (self->_onLoadingStart) {
1111+
// We have this check to filter out iframe requests and whatnot
1112+
if (isTopFrame) {
1113+
NSMutableDictionary<NSString *, id> *event = [self baseEvent];
1114+
[event addEntriesFromDictionary: @{
1115+
@"url": (request.URL).absoluteString,
1116+
@"navigationType": navigationTypes[@(navigationType)]
1117+
}];
1118+
self->_onLoadingStart(event);
1119+
}
1120+
}
1121+
decisionHandler(WKNavigationActionPolicyAllow);
1122+
};
1123+
11091124
if (_onShouldStartLoadWithRequest) {
11101125
NSMutableDictionary<NSString *, id> *event = [self baseEvent];
11111126
if (request.mainDocumentURL) {
@@ -1126,20 +1141,8 @@ - (void) webView:(WKWebView *)webView
11261141
}
11271142
}
11281143

1129-
if (_onLoadingStart) {
1130-
// We have this check to filter out iframe requests and whatnot
1131-
if (isTopFrame) {
1132-
NSMutableDictionary<NSString *, id> *event = [self baseEvent];
1133-
[event addEntriesFromDictionary: @{
1134-
@"url": (request.URL).absoluteString,
1135-
@"navigationType": navigationTypes[@(navigationType)]
1136-
}];
1137-
_onLoadingStart(event);
1138-
}
1139-
}
1140-
11411144
// Allow all navigation by default
1142-
decisionHandler(WKNavigationActionPolicyAllow);
1145+
allowNavigation();
11431146
}
11441147

11451148
/**

0 commit comments

Comments
 (0)