From 33b353c97c31190439a22febbd3d2a9ead49d3c9 Mon Sep 17 00:00:00 2001 From: Ramanpreet Nara Date: Thu, 16 Aug 2018 13:34:35 -0700 Subject: [PATCH] Gate usage of WebKit 10.0 APIs Reviewed By: mmmulani Differential Revision: D9362001 fbshipit-source-id: 62cde6bcc1f190c168973b173ce55c029328bfbf --- React/Base/RCTConvert.h | 2 +- React/Base/RCTConvert.m | 5 ++++- React/Base/RCTDefines.h | 5 +++++ React/Views/RCTWKWebView.h | 3 +++ React/Views/RCTWKWebView.m | 4 +++- React/Views/RCTWKWebViewManager.m | 5 ++++- 6 files changed, 20 insertions(+), 4 deletions(-) diff --git a/React/Base/RCTConvert.h b/React/Base/RCTConvert.h index dff41ec13..ae2851f38 100644 --- a/React/Base/RCTConvert.h +++ b/React/Base/RCTConvert.h @@ -71,7 +71,7 @@ typedef NSURL RCTFileURL; + (UIDataDetectorTypes)UIDataDetectorTypes:(id)json; #endif -#if TARGET_OS_IPHONE +#if TARGET_OS_IPHONE && WEBKIT_IOS_10_APIS_AVAILABLE + (WKDataDetectorTypes)WKDataDetectorTypes:(id)json; #endif diff --git a/React/Base/RCTConvert.m b/React/Base/RCTConvert.m index 90335e989..673cef703 100644 --- a/React/Base/RCTConvert.m +++ b/React/Base/RCTConvert.m @@ -362,6 +362,7 @@ RCT_MULTI_ENUM_CONVERTER(UIDataDetectorTypes, (@{ @"all": @(UIDataDetectorTypeAll), }), UIDataDetectorTypePhoneNumber, unsignedLongLongValue) +#if WEBKIT_IOS_10_APIS_AVAILABLE RCT_MULTI_ENUM_CONVERTER(WKDataDetectorTypes, (@{ @"phoneNumber": @(WKDataDetectorTypePhoneNumber), @"link": @(WKDataDetectorTypeLink), @@ -373,7 +374,9 @@ RCT_MULTI_ENUM_CONVERTER(WKDataDetectorTypes, (@{ @"none": @(WKDataDetectorTypeNone), @"all": @(WKDataDetectorTypeAll), }), WKDataDetectorTypePhoneNumber, unsignedLongLongValue) -#endif + #endif // WEBKIT_IOS_10_APIS_AVAILABLE + + #endif // !TARGET_OS_TV RCT_ENUM_CONVERTER(UIKeyboardAppearance, (@{ @"default": @(UIKeyboardAppearanceDefault), diff --git a/React/Base/RCTDefines.h b/React/Base/RCTDefines.h index 881af139d..da0e91878 100644 --- a/React/Base/RCTDefines.h +++ b/React/Base/RCTDefines.h @@ -125,3 +125,8 @@ _Pragma("clang diagnostic ignored \"-Wunused-parameter\"") \ RCT_EXTERN NSException *_RCTNotImplementedException(SEL, Class); \ method NS_UNAVAILABLE { @throw _RCTNotImplementedException(_cmd, [self class]); } \ _Pragma("clang diagnostic pop") + +/** + * Check if WebKit iOS 10.0 APIs are available. + */ +#define WEBKIT_IOS_10_APIS_AVAILABLE __has_include() diff --git a/React/Views/RCTWKWebView.h b/React/Views/RCTWKWebView.h index 62c137108..e70a1cca1 100644 --- a/React/Views/RCTWKWebView.h +++ b/React/Views/RCTWKWebView.h @@ -8,6 +8,7 @@ */ #import +#import #import @class RCTWKWebView; @@ -31,7 +32,9 @@ shouldStartLoadForRequest:(NSMutableDictionary *)request @property (nonatomic, assign) BOOL allowsInlineMediaPlayback; @property (nonatomic, assign) BOOL bounces; @property (nonatomic, assign) BOOL mediaPlaybackRequiresUserAction; +#if WEBKIT_IOS_10_APIS_AVAILABLE @property (nonatomic, assign) WKDataDetectorTypes dataDetectorTypes; +#endif @property (nonatomic, assign) UIEdgeInsets contentInset; @property (nonatomic, assign) BOOL automaticallyAdjustContentInsets; diff --git a/React/Views/RCTWKWebView.m b/React/Views/RCTWKWebView.m index 71c2d88de..02a66c1cc 100644 --- a/React/Views/RCTWKWebView.m +++ b/React/Views/RCTWKWebView.m @@ -65,10 +65,12 @@ static NSString *const MessageHanderName = @"ReactNative"; wkWebViewConfig.userContentController = [WKUserContentController new]; [wkWebViewConfig.userContentController addScriptMessageHandler: self name: MessageHanderName]; wkWebViewConfig.allowsInlineMediaPlayback = _allowsInlineMediaPlayback; +#if WEBKIT_IOS_10_APIS_AVAILABLE wkWebViewConfig.mediaTypesRequiringUserActionForPlayback = _mediaPlaybackRequiresUserAction ? WKAudiovisualMediaTypeAll : WKAudiovisualMediaTypeNone; - wkWebViewConfig.dataDetectorTypes = _dataDetectorTypes; + wkWebViewConfig.dataDetectorTypes = _dataDetectorTypes; +#endif _webView = [[WKWebView alloc] initWithFrame:self.bounds configuration: wkWebViewConfig]; _webView.scrollView.delegate = self; diff --git a/React/Views/RCTWKWebViewManager.m b/React/Views/RCTWKWebViewManager.m index f03801855..31e2655e1 100644 --- a/React/Views/RCTWKWebViewManager.m +++ b/React/Views/RCTWKWebViewManager.m @@ -2,6 +2,7 @@ #import "RCTUIManager.h" #import "RCTWKWebView.h" +#import @interface RCTWKWebViewManager () @end @@ -29,10 +30,12 @@ RCT_EXPORT_VIEW_PROPERTY(onShouldStartLoadWithRequest, RCTDirectEventBlock) RCT_EXPORT_VIEW_PROPERTY(injectedJavaScript, NSString) RCT_EXPORT_VIEW_PROPERTY(allowsInlineMediaPlayback, BOOL) RCT_EXPORT_VIEW_PROPERTY(mediaPlaybackRequiresUserAction, BOOL) +#if WEBKIT_IOS_10_APIS_AVAILABLE RCT_EXPORT_VIEW_PROPERTY(dataDetectorTypes, WKDataDetectorTypes) +#endif RCT_EXPORT_VIEW_PROPERTY(contentInset, UIEdgeInsets) RCT_EXPORT_VIEW_PROPERTY(automaticallyAdjustContentInsets, BOOL) - + /** * Expose methods to enable messaging the webview. */