Browse Source

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

StasD 5 years ago
parent
commit
88b64981f4
4 changed files with 17 additions and 7 deletions
  1. 7
    7
      docs/Reference.md
  2. 1
    0
      ios/RNCWebView.h
  3. 8
    0
      ios/RNCWebView.m
  4. 1
    0
      ios/RNCWebViewManager.m

+ 7
- 7
docs/Reference.md View File

686
 
686
 
687
 ### `javaScriptEnabled`
687
 ### `javaScriptEnabled`
688
 
688
 
689
-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`.
689
+Boolean value to enable JavaScript in the `WebView`. The default value is `true`.
690
 
690
 
691
-| Type | Required | Platform |
692
-| ---- | -------- | -------- |
693
-| bool | No       | Android  |
691
+| Type | Required |
692
+| ---- | -------- |
693
+| bool | No       |
694
 
694
 
695
 ---
695
 ---
696
 
696
 
914
 
914
 
915
 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`.
915
 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`.
916
 
916
 
917
-| Type | Required | Platform |
918
-| ---- | -------- | -------- |
919
-| bool | No       | Android  |
917
+| Type | Required |
918
+| ---- | -------- |
919
+| bool | No       |
920
 
920
 
921
 ---
921
 ---
922
 
922
 

+ 1
- 0
ios/RNCWebView.h View File

47
 @property (nonatomic, copy) NSString * _Nullable applicationNameForUserAgent;
47
 @property (nonatomic, copy) NSString * _Nullable applicationNameForUserAgent;
48
 @property (nonatomic, assign) BOOL cacheEnabled;
48
 @property (nonatomic, assign) BOOL cacheEnabled;
49
 @property (nonatomic, assign) BOOL javaScriptEnabled;
49
 @property (nonatomic, assign) BOOL javaScriptEnabled;
50
+@property (nonatomic, assign) BOOL allowFileAccessFromFileURLs;
50
 @property (nonatomic, assign) BOOL allowsLinkPreview;
51
 @property (nonatomic, assign) BOOL allowsLinkPreview;
51
 @property (nonatomic, assign) BOOL showsHorizontalScrollIndicator;
52
 @property (nonatomic, assign) BOOL showsHorizontalScrollIndicator;
52
 @property (nonatomic, assign) BOOL showsVerticalScrollIndicator;
53
 @property (nonatomic, assign) BOOL showsVerticalScrollIndicator;

+ 8
- 0
ios/RNCWebView.m View File

138
   if (self.window != nil && _webView == nil) {
138
   if (self.window != nil && _webView == nil) {
139
     WKWebViewConfiguration *wkWebViewConfig = [WKWebViewConfiguration new];
139
     WKWebViewConfiguration *wkWebViewConfig = [WKWebViewConfiguration new];
140
     WKPreferences *prefs = [[WKPreferences alloc]init];
140
     WKPreferences *prefs = [[WKPreferences alloc]init];
141
+    BOOL _prefsUsed = NO;
141
     if (!_javaScriptEnabled) {
142
     if (!_javaScriptEnabled) {
142
       prefs.javaScriptEnabled = NO;
143
       prefs.javaScriptEnabled = NO;
144
+      _prefsUsed = YES;
145
+    }
146
+    if (_allowFileAccessFromFileURLs) {
147
+      [prefs setValue:@TRUE forKey:@"allowFileAccessFromFileURLs"];
148
+      _prefsUsed = YES;
149
+    }
150
+    if (_prefsUsed) {
143
       wkWebViewConfig.preferences = prefs;
151
       wkWebViewConfig.preferences = prefs;
144
     }
152
     }
145
     if (_incognito) {
153
     if (_incognito) {

+ 1
- 0
ios/RNCWebViewManager.m View File

53
 RCT_EXPORT_VIEW_PROPERTY(injectedJavaScript, NSString)
53
 RCT_EXPORT_VIEW_PROPERTY(injectedJavaScript, NSString)
54
 RCT_EXPORT_VIEW_PROPERTY(injectedJavaScriptBeforeContentLoaded, NSString)
54
 RCT_EXPORT_VIEW_PROPERTY(injectedJavaScriptBeforeContentLoaded, NSString)
55
 RCT_EXPORT_VIEW_PROPERTY(javaScriptEnabled, BOOL)
55
 RCT_EXPORT_VIEW_PROPERTY(javaScriptEnabled, BOOL)
56
+RCT_EXPORT_VIEW_PROPERTY(allowFileAccessFromFileURLs, BOOL)
56
 RCT_EXPORT_VIEW_PROPERTY(allowsInlineMediaPlayback, BOOL)
57
 RCT_EXPORT_VIEW_PROPERTY(allowsInlineMediaPlayback, BOOL)
57
 RCT_EXPORT_VIEW_PROPERTY(mediaPlaybackRequiresUserAction, BOOL)
58
 RCT_EXPORT_VIEW_PROPERTY(mediaPlaybackRequiresUserAction, BOOL)
58
 #if WEBKIT_IOS_10_APIS_AVAILABLE
59
 #if WEBKIT_IOS_10_APIS_AVAILABLE