Gate usage of WebKit 10.0 APIs

Reviewed By: mmmulani

Differential Revision: D9362001

fbshipit-source-id: 62cde6bcc1f190c168973b173ce55c029328bfbf
This commit is contained in:
Ramanpreet Nara 2018-08-16 13:34:35 -07:00 committed by Facebook Github Bot
parent 28b058c341
commit 33b353c97c
6 changed files with 20 additions and 4 deletions

View File

@ -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

View File

@ -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),

View File

@ -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(<WebKit/WKAudiovisualMediaTypes.h>)

View File

@ -8,6 +8,7 @@
*/
#import <React/RCTView.h>
#import <React/RCTDefines.h>
#import <WebKit/WebKit.h>
@class RCTWKWebView;
@ -31,7 +32,9 @@ shouldStartLoadForRequest:(NSMutableDictionary<NSString *, id> *)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;

View File

@ -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;

View File

@ -2,6 +2,7 @@
#import "RCTUIManager.h"
#import "RCTWKWebView.h"
#import <React/RCTDefines.h>
@interface RCTWKWebViewManager () <RCTWKWebViewDelegate>
@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.
*/