Skip to content

Commit a9537cf

Browse files
committed
Dont block on urls loaded from the api
1 parent 3793ee0 commit a9537cf

1 file changed

Lines changed: 16 additions & 12 deletions

File tree

AQWebView/AQWebView.m

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ @interface AQWebView () <RCTAutoInsetsProtocol, WKNavigationDelegate>
1111
@property (nonatomic, copy) RCTDirectEventBlock onLoadingFinish;
1212
@property (nonatomic, copy) RCTDirectEventBlock onLoadingError;
1313
@property (nonatomic, copy) RCTDirectEventBlock onPrefixBlocked;
14-
14+
@property (nonatomic, strong) NSString *userLoadedUrl;
1515
@end
1616

1717
@implementation AQWebView
@@ -78,6 +78,7 @@ - (void)setSource:(NSDictionary *)source
7878
NSString *html = [RCTConvert NSString:source[@"html"]];
7979
if (html) {
8080
NSURL *baseURL = [RCTConvert NSURL:source[@"baseUrl"]];
81+
_userLoadedUrl = [baseURL absoluteString];
8182
[_webView loadHTMLString:html baseURL:baseURL];
8283
return;
8384
}
@@ -95,6 +96,7 @@ - (void)setSource:(NSDictionary *)source
9596
[_webView loadHTMLString:@"" baseURL:nil];
9697
return;
9798
}
99+
_userLoadedUrl = [request.URL absoluteString];
98100
[_webView loadRequest:request];
99101
}
100102
}
@@ -159,17 +161,19 @@ - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigati
159161
urlStr = @"about:blank";
160162
}
161163

162-
for (id prefix in _blockedPrefixes) {
163-
if ([urlStr hasPrefix:prefix]) {
164-
NSMutableDictionary<NSString *, id> *event = [[NSMutableDictionary alloc] initWithDictionary:
165-
@{
166-
@"url": urlStr,
167-
}
168-
];
169-
_onPrefixBlocked(event);
170-
decisionHandler(WKNavigationActionPolicyCancel);
171-
block = true;
172-
break;
164+
if (![urlStr isEqual: _userLoadedUrl]) {
165+
for (id prefix in _blockedPrefixes) {
166+
if ([urlStr hasPrefix:prefix]) {
167+
NSMutableDictionary<NSString *, id> *event = [[NSMutableDictionary alloc] initWithDictionary:
168+
@{
169+
@"url": urlStr,
170+
}
171+
];
172+
_onPrefixBlocked(event);
173+
decisionHandler(WKNavigationActionPolicyCancel);
174+
block = true;
175+
break;
176+
}
173177
}
174178
}
175179

0 commit comments

Comments
 (0)