Implement 'reload' and 'stopLoading' methods

Summary:
@public

This diff implements the `reload` and `stopLoading` methods for `WKWebView`. Their functionality is self-explanatory.

Reviewed By: shergin

Differential Revision: D6369292

fbshipit-source-id: ba176f4406e0a67606406f36dd66f7615f4796c3
This commit is contained in:
Ramanpreet Nara 2018-08-16 13:34:14 -07:00 коммит произвёл Facebook Github Bot
Родитель 03b57d9db6
Коммит 1584108805
3 изменённых файлов: 46 добавлений и 0 удалений

Просмотреть файл

@ -27,5 +27,7 @@
- (void)injectJavaScript:(NSString *)script;
- (void)goForward;
- (void)goBack;
- (void)reload;
- (void)stopLoading;
@end

Просмотреть файл

@ -270,4 +270,24 @@ static NSString *const MessageHanderName = @"ReactNative";
[_webView goBack];
}
- (void)reload
{
/**
* When the initial load fails due to network connectivity issues,
* [_webView reload] doesn't reload the webpage. Therefore, we must
* manually call [_webView loadRequest:request].
*/
NSURLRequest *request = [RCTConvert NSURLRequest:self.source];
if (request.URL && !_webView.URL.absoluteString.length) {
[_webView loadRequest:request];
}
else {
[_webView reload];
}
}
- (void)stopLoading
{
[_webView stopLoading];
}
@end

Просмотреть файл

@ -81,4 +81,28 @@ RCT_EXPORT_METHOD(goForward:(nonnull NSNumber *)reactTag)
}];
}
RCT_EXPORT_METHOD(reload:(nonnull NSNumber *)reactTag)
{
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTWKWebView *> *viewRegistry) {
RCTWKWebView *view = viewRegistry[reactTag];
if (![view isKindOfClass:[RCTWKWebView class]]) {
RCTLogError(@"Invalid view returned from registry, expecting RCTWebView, got: %@", view);
} else {
[view reload];
}
}];
}
RCT_EXPORT_METHOD(stopLoading:(nonnull NSNumber *)reactTag)
{
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTWKWebView *> *viewRegistry) {
RCTWKWebView *view = viewRegistry[reactTag];
if (![view isKindOfClass:[RCTWKWebView class]]) {
RCTLogError(@"Invalid view returned from registry, expecting RCTWebView, got: %@", view);
} else {
[view stopLoading];
}
}];
}
@end