mirror of
https://github.com/status-im/react-native.git
synced 2025-02-25 15:45:32 +00:00
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:
parent
03b57d9db6
commit
1584108805
@ -27,5 +27,7 @@
|
|||||||
- (void)injectJavaScript:(NSString *)script;
|
- (void)injectJavaScript:(NSString *)script;
|
||||||
- (void)goForward;
|
- (void)goForward;
|
||||||
- (void)goBack;
|
- (void)goBack;
|
||||||
|
- (void)reload;
|
||||||
|
- (void)stopLoading;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -270,4 +270,24 @@ static NSString *const MessageHanderName = @"ReactNative";
|
|||||||
[_webView goBack];
|
[_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
|
@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
|
@end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user