Browse Source

feat(android): allowFileAccessFromFileURLs prop added (#831)

* add allowFileAccessFromFileURLs propery to do the expected on android

* Added types

* Update WebViewTypes.ts
Borut Balazek 4 years ago
parent
commit
4db3d84dda

+ 5
- 0
android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java View File

@@ -371,6 +371,11 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
371 371
     view.getSettings().setMediaPlaybackRequiresUserGesture(requires);
372 372
   }
373 373
 
374
+  @ReactProp(name = "allowFileAccessFromFileURLs")
375
+  public void setAllowFileAccessFromFileURLs(WebView view, boolean allow) {
376
+    view.getSettings().setAllowFileAccessFromFileURLs(allow);
377
+  }
378
+
374 379
   @ReactProp(name = "allowUniversalAccessFromFileURLs")
375 380
   public void setAllowUniversalAccessFromFileURLs(WebView view, boolean allow) {
376 381
     view.getSettings().setAllowUniversalAccessFromFileURLs(allow);

+ 11
- 0
docs/Reference.md View File

@@ -44,6 +44,7 @@ This document lays out the current public properties and methods for the React N
44 44
 - [`scrollEnabled`](Reference.md#scrollenabled)
45 45
 - [`directionalLockEnabled`](Reference.md#directionalLockEnabled)
46 46
 - [`geolocationEnabled`](Reference.md#geolocationenabled)
47
+- [`allowFileAccessFromFileURLs`](Reference.md#allowFileAccessFromFileURLs)
47 48
 - [`allowUniversalAccessFromFileURLs`](Reference.md#allowUniversalAccessFromFileURLs)
48 49
 - [`allowingReadAccessToURL`](Reference.md#allowingReadAccessToURL)
49 50
 - [`url`](Reference.md#url)
@@ -876,6 +877,16 @@ Set whether Geolocation is enabled in the `WebView`. The default value is `false
876 877
 
877 878
 ---
878 879
 
880
+### `allowFileAccessFromFileURLs`
881
+
882
+ 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`.
883
+
884
+| Type | Required | Platform |
885
+| ---- | -------- | -------- |
886
+| bool | No       | Android  |
887
+
888
+---
889
+
879 890
 ### `allowUniversalAccessFromFileURLs`
880 891
 
881 892
 Boolean that sets whether JavaScript running in the context of a file scheme URL should be allowed to access content from any origin. Including accessing content from other file scheme URLs. The default value is `false`.

+ 10
- 0
src/WebViewTypes.ts View File

@@ -242,6 +242,7 @@ export interface AndroidNativeWebViewProps extends CommonNativeWebViewProps {
242 242
   cacheMode?: CacheMode;
243 243
   allowFileAccess?: boolean;
244 244
   scalesPageToFit?: boolean;
245
+  allowFileAccessFromFileURLs?: boolean;
245 246
   allowUniversalAccessFromFileURLs?: boolean;
246 247
   androidHardwareAccelerationDisabled?: boolean;
247 248
   domStorageEnabled?: boolean;
@@ -500,6 +501,15 @@ export interface AndroidWebViewProps extends WebViewSharedProps {
500 501
    */
501 502
   geolocationEnabled?: boolean;
502 503
 
504
+  
505
+  /**
506
+   * Boolean that sets whether JavaScript running in the context of a file 
507
+   * scheme URL should be allowed to access content from other file scheme URLs. 
508
+   * Including accessing content from other file scheme URLs
509
+   * @platform android
510
+   */
511
+  allowFileAccessFromFileURLs?: boolean;
512
+  
503 513
   /**
504 514
    * Boolean that sets whether JavaScript running in the context of a file
505 515
    * scheme URL should be allowed to access content from any origin.