fix(ios): Make allowFileAccessFromFileURLs work in iOS. (#1061)

This commit is contained in:
StasD 2019-12-06 21:16:56 +11:00 committed by Thibault Malbranche
parent 604495e399
commit 88b64981f4
4 changed files with 17 additions and 7 deletions

View File

@ -686,11 +686,11 @@ Boolean value to control whether DOM Storage is enabled. Used only in Android.
### `javaScriptEnabled`
Boolean value to enable JavaScript in the `WebView`. Used on Android only as JavaScript is enabled by default on iOS. The default value is `true`.
Boolean value to enable JavaScript in the `WebView`. The default value is `true`.
| Type | Required | Platform |
| ---- | -------- | -------- |
| bool | No | Android |
| Type | Required |
| ---- | -------- |
| bool | No |
---
@ -914,9 +914,9 @@ Set whether Geolocation is enabled in the `WebView`. The default value is `false
Boolean that sets whether JavaScript running in the context of a file scheme URL should be allowed to access content from other file scheme URLs. The default value is `false`.
| Type | Required | Platform |
| ---- | -------- | -------- |
| bool | No | Android |
| Type | Required |
| ---- | -------- |
| bool | No |
---

View File

@ -47,6 +47,7 @@
@property (nonatomic, copy) NSString * _Nullable applicationNameForUserAgent;
@property (nonatomic, assign) BOOL cacheEnabled;
@property (nonatomic, assign) BOOL javaScriptEnabled;
@property (nonatomic, assign) BOOL allowFileAccessFromFileURLs;
@property (nonatomic, assign) BOOL allowsLinkPreview;
@property (nonatomic, assign) BOOL showsHorizontalScrollIndicator;
@property (nonatomic, assign) BOOL showsVerticalScrollIndicator;

View File

@ -138,8 +138,16 @@ static NSDictionary* customCertificatesForHost;
if (self.window != nil && _webView == nil) {
WKWebViewConfiguration *wkWebViewConfig = [WKWebViewConfiguration new];
WKPreferences *prefs = [[WKPreferences alloc]init];
BOOL _prefsUsed = NO;
if (!_javaScriptEnabled) {
prefs.javaScriptEnabled = NO;
_prefsUsed = YES;
}
if (_allowFileAccessFromFileURLs) {
[prefs setValue:@TRUE forKey:@"allowFileAccessFromFileURLs"];
_prefsUsed = YES;
}
if (_prefsUsed) {
wkWebViewConfig.preferences = prefs;
}
if (_incognito) {

View File

@ -53,6 +53,7 @@ RCT_EXPORT_VIEW_PROPERTY(onContentProcessDidTerminate, RCTDirectEventBlock)
RCT_EXPORT_VIEW_PROPERTY(injectedJavaScript, NSString)
RCT_EXPORT_VIEW_PROPERTY(injectedJavaScriptBeforeContentLoaded, NSString)
RCT_EXPORT_VIEW_PROPERTY(javaScriptEnabled, BOOL)
RCT_EXPORT_VIEW_PROPERTY(allowFileAccessFromFileURLs, BOOL)
RCT_EXPORT_VIEW_PROPERTY(allowsInlineMediaPlayback, BOOL)
RCT_EXPORT_VIEW_PROPERTY(mediaPlaybackRequiresUserAction, BOOL)
#if WEBKIT_IOS_10_APIS_AVAILABLE