Permalink
Browse files

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
  • Loading branch information...
RSNara authored and kelset committed Aug 16, 2018
1 parent 1984f4b commit 1b73e76ff374e45ee92f4866f963afff4978277e
Showing with 36 additions and 0 deletions.
  1. +2 −0 React/Views/RCTWKWebView.h
  2. +10 −0 React/Views/RCTWKWebView.m
  3. +24 −0 React/Views/RCTWKWebViewManager.m
@@ -25,5 +25,7 @@
- (void)postMessage:(NSString *)message;
- (void)injectJavaScript:(NSString *)script;
- (void)goForward;
- (void)goBack;
@end
View
@@ -260,4 +260,14 @@ - (void)injectJavaScript:(NSString *)script
[self evaluateJS: script thenCall: nil];
}
- (void)goForward
{
[_webView goForward];
}
- (void)goBack
{
[_webView goBack];
}
@end
@@ -57,4 +57,28 @@ - (UIView *)view
}];
}
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

0 comments on commit 1b73e76

Please sign in to comment.