diff --git a/React/Views/RCTWKWebView.h b/React/Views/RCTWKWebView.h index e9143033c..62c137108 100644 --- a/React/Views/RCTWKWebView.h +++ b/React/Views/RCTWKWebView.h @@ -32,6 +32,8 @@ shouldStartLoadForRequest:(NSMutableDictionary *)request @property (nonatomic, assign) BOOL bounces; @property (nonatomic, assign) BOOL mediaPlaybackRequiresUserAction; @property (nonatomic, assign) WKDataDetectorTypes dataDetectorTypes; +@property (nonatomic, assign) UIEdgeInsets contentInset; +@property (nonatomic, assign) BOOL automaticallyAdjustContentInsets; - (void)postMessage:(NSString *)message; - (void)injectJavaScript:(NSString *)script; diff --git a/React/Views/RCTWKWebView.m b/React/Views/RCTWKWebView.m index 0a55fdccd..2488ff209 100644 --- a/React/Views/RCTWKWebView.m +++ b/React/Views/RCTWKWebView.m @@ -4,7 +4,7 @@ static NSString *const MessageHanderName = @"ReactNative"; -@interface RCTWKWebView () +@interface RCTWKWebView () @property (nonatomic, copy) RCTDirectEventBlock onLoadingStart; @property (nonatomic, copy) RCTDirectEventBlock onLoadingFinish; @property (nonatomic, copy) RCTDirectEventBlock onLoadingError; @@ -29,6 +29,8 @@ static NSString *const MessageHanderName = @"ReactNative"; super.backgroundColor = [UIColor clearColor]; _bounces = YES; _scrollEnabled = YES; + _automaticallyAdjustContentInsets = YES; + _contentInset = UIEdgeInsetsZero; } return self; } @@ -51,6 +53,13 @@ static NSString *const MessageHanderName = @"ReactNative"; _webView.navigationDelegate = self; _webView.scrollView.scrollEnabled = _scrollEnabled; _webView.scrollView.bounces = _bounces; + +#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */ + if ([_webView.scrollView respondsToSelector:@selector(setContentInsetAdjustmentBehavior:)]) { + _webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; + } +#endif + [self addSubview:_webView]; [self visitSource]; @@ -95,6 +104,21 @@ static NSString *const MessageHanderName = @"ReactNative"; } } +- (void)setContentInset:(UIEdgeInsets)contentInset +{ + _contentInset = contentInset; + [RCTView autoAdjustInsetsForView:self + withScrollView:_webView.scrollView + updateOffset:NO]; +} + +- (void)refreshContentInset +{ + [RCTView autoAdjustInsetsForView:self + withScrollView:_webView.scrollView + updateOffset:YES]; +} + - (void)visitSource { // Check for a static html source first diff --git a/React/Views/RCTWKWebViewManager.m b/React/Views/RCTWKWebViewManager.m index b3b0f0b43..f03801855 100644 --- a/React/Views/RCTWKWebViewManager.m +++ b/React/Views/RCTWKWebViewManager.m @@ -30,6 +30,8 @@ RCT_EXPORT_VIEW_PROPERTY(injectedJavaScript, NSString) RCT_EXPORT_VIEW_PROPERTY(allowsInlineMediaPlayback, BOOL) RCT_EXPORT_VIEW_PROPERTY(mediaPlaybackRequiresUserAction, BOOL) RCT_EXPORT_VIEW_PROPERTY(dataDetectorTypes, WKDataDetectorTypes) +RCT_EXPORT_VIEW_PROPERTY(contentInset, UIEdgeInsets) +RCT_EXPORT_VIEW_PROPERTY(automaticallyAdjustContentInsets, BOOL) /** * Expose methods to enable messaging the webview.