diff --git a/React/Views/RCTWKWebView.h b/React/Views/RCTWKWebView.h index b0f073a67..ce9b07347 100644 --- a/React/Views/RCTWKWebView.h +++ b/React/Views/RCTWKWebView.h @@ -25,5 +25,7 @@ - (void)postMessage:(NSString *)message; - (void)injectJavaScript:(NSString *)script; +- (void)goForward; +- (void)goBack; @end diff --git a/React/Views/RCTWKWebView.m b/React/Views/RCTWKWebView.m index 4083f1a5f..b2dbc1203 100644 --- a/React/Views/RCTWKWebView.m +++ b/React/Views/RCTWKWebView.m @@ -260,4 +260,14 @@ static NSString *const MessageHanderName = @"ReactNative"; [self evaluateJS: script thenCall: nil]; } +- (void)goForward +{ + [_webView goForward]; +} + +- (void)goBack +{ + [_webView goBack]; +} + @end diff --git a/React/Views/RCTWKWebViewManager.m b/React/Views/RCTWKWebViewManager.m index f6e3a0371..0fee19310 100644 --- a/React/Views/RCTWKWebViewManager.m +++ b/React/Views/RCTWKWebViewManager.m @@ -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 *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 *viewRegistry) { + RCTWKWebView *view = viewRegistry[reactTag]; + if (![view isKindOfClass:[RCTWKWebView class]]) { + RCTLogError(@"Invalid view returned from registry, expecting RCTWebView, got: %@", view); + } else { + [view goForward]; + } + }]; +} + @end