Implement 'goForward' and 'goBack' methods
Summary: @public This diff implements the `goForward` and `goBack` methods on `WKWebView`. 1. `goForward` moves the web view one screen forward in the browser history. 1. `goBack` moves the web view one screen back in the browser history. Reviewed By: shergin Differential Revision: D6367495 fbshipit-source-id: e100ca00e92a6eaa30d2af1af642ba79a9c9feae
This commit is contained in:
parent
0022354525
commit
03b57d9db6
|
@ -25,5 +25,7 @@
|
|||
|
||||
- (void)postMessage:(NSString *)message;
|
||||
- (void)injectJavaScript:(NSString *)script;
|
||||
- (void)goForward;
|
||||
- (void)goBack;
|
||||
|
||||
@end
|
||||
|
|
|
@ -260,4 +260,14 @@ static NSString *const MessageHanderName = @"ReactNative";
|
|||
[self evaluateJS: script thenCall: nil];
|
||||
}
|
||||
|
||||
- (void)goForward
|
||||
{
|
||||
[_webView goForward];
|
||||
}
|
||||
|
||||
- (void)goBack
|
||||
{
|
||||
[_webView goBack];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -57,4 +57,28 @@ RCT_EXPORT_METHOD(injectJavaScript:(nonnull NSNumber *)reactTag script:(NSString
|
|||
}];
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(goBack:(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 goBack];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(goForward:(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 goForward];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Loading…
Reference in New Issue