Browse Source

feat(android): Add androidLayerType as prop (#1588)

* Add androidLayerType as a prop

* Deprecate "androidHardwareAccelerationDisabled" prop

* Update reference

Co-authored-by: Olivia Caraiman <olcaraim@microsoft.com>
oliviacaraiman 4 years ago
parent
commit
9ffca8f9db
No account linked to committer's email address

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

299
     }
299
     }
300
   }
300
   }
301
 
301
 
302
+  @ReactProp(name = "androidLayerType")
303
+  public void setLayerType(WebView view, String layerTypeString) {
304
+    int layerType = View.LAYER_TYPE_NONE;
305
+    switch (layerTypeString) {
306
+        case "hardware":
307
+          layerType = View.LAYER_TYPE_HARDWARE;
308
+          break;
309
+        case "software":
310
+          layerType = View.LAYER_TYPE_SOFTWARE;
311
+          break;
312
+    }
313
+    view.setLayerType(layerType, null);
314
+  }
315
+
316
+
302
   @ReactProp(name = "overScrollMode")
317
   @ReactProp(name = "overScrollMode")
303
   public void setOverScrollMode(WebView view, String overScrollModeString) {
318
   public void setOverScrollMode(WebView view, String overScrollModeString) {
304
     Integer overScrollMode;
319
     Integer overScrollMode;

+ 20
- 1
docs/Reference.md View File

35
 - [`javaScriptEnabled`](Reference.md#javascriptenabled)
35
 - [`javaScriptEnabled`](Reference.md#javascriptenabled)
36
 - [`javaScriptCanOpenWindowsAutomatically`](Reference.md#javascriptcanopenwindowsautomatically)
36
 - [`javaScriptCanOpenWindowsAutomatically`](Reference.md#javascriptcanopenwindowsautomatically)
37
 - [`androidHardwareAccelerationDisabled`](Reference.md#androidHardwareAccelerationDisabled)
37
 - [`androidHardwareAccelerationDisabled`](Reference.md#androidHardwareAccelerationDisabled)
38
+- [`androidLayerType`](Reference.md#androidLayerType)
38
 - [`mixedContentMode`](Reference.md#mixedcontentmode)
39
 - [`mixedContentMode`](Reference.md#mixedcontentmode)
39
 - [`thirdPartyCookiesEnabled`](Reference.md#thirdpartycookiesenabled)
40
 - [`thirdPartyCookiesEnabled`](Reference.md#thirdpartycookiesenabled)
40
 - [`userAgent`](Reference.md#useragent)
41
 - [`userAgent`](Reference.md#useragent)
781
 
782
 
782
 ### `androidHardwareAccelerationDisabled`[⬆](#props-index)<!-- Link generated with jump2header -->
783
 ### `androidHardwareAccelerationDisabled`[⬆](#props-index)<!-- Link generated with jump2header -->
783
 
784
 
784
-Boolean value to disable Hardware Acceleration in the `WebView`. Used on Android only as Hardware Acceleration is a feature only for Android. The default value is `false`.
785
+**Deprecated.** Use the `androidLayerType` prop instead. 
785
 
786
 
786
 | Type | Required | Platform |
787
 | Type | Required | Platform |
787
 | ---- | -------- | -------- |
788
 | ---- | -------- | -------- |
789
 
790
 
790
 ---
791
 ---
791
 
792
 
793
+### `androidLayerType`[⬆](#props-index)<!-- Link generated with jump2header -->
794
+
795
+Specifies the layer type. 
796
+
797
+Possible values for `androidLayerType` are:
798
+
799
+- `none` (default) - The view does not have a layer.
800
+- `software` - The view has a software layer. A software layer is backed by a bitmap and causes the view to be rendered using Android's software rendering pipeline, even if hardware acceleration is enabled.
801
+- `hardware` - The view has a hardware layer. A hardware layer is backed by a hardware specific texture and causes the view to be rendered using Android's hardware rendering pipeline, but only if hardware acceleration is turned on for the view hierarchy.
802
+
803
+Avoid setting both `androidLayerType` and `androidHardwareAccelerationDisabled` props at the same time, as this may cause undefined behaviour.
804
+
805
+| Type   | Required | Platform |
806
+| ------ | -------- | -------- |
807
+| string | No       | Android  |
808
+
809
+---
810
+
792
 ### `mixedContentMode`[⬆](#props-index)<!-- Link generated with jump2header -->
811
 ### `mixedContentMode`[⬆](#props-index)<!-- Link generated with jump2header -->
793
 
812
 
794
 Specifies the mixed content mode. i.e WebView will allow a secure origin to load content from any other origin.
813
 Specifies the mixed content mode. i.e WebView will allow a secure origin to load content from any other origin.

+ 1
- 0
src/WebView.android.tsx View File

61
     saveFormDataDisabled: false,
61
     saveFormDataDisabled: false,
62
     cacheEnabled: true,
62
     cacheEnabled: true,
63
     androidHardwareAccelerationDisabled: false,
63
     androidHardwareAccelerationDisabled: false,
64
+    androidLayerType: 'none',
64
     originWhitelist: defaultOriginWhitelist,
65
     originWhitelist: defaultOriginWhitelist,
65
   };
66
   };
66
 
67
 

+ 15
- 0
src/WebViewTypes.ts View File

182
 
182
 
183
 export type CacheMode = 'LOAD_DEFAULT' | 'LOAD_CACHE_ONLY' | 'LOAD_CACHE_ELSE_NETWORK' | 'LOAD_NO_CACHE';
183
 export type CacheMode = 'LOAD_DEFAULT' | 'LOAD_CACHE_ONLY' | 'LOAD_CACHE_ELSE_NETWORK' | 'LOAD_NO_CACHE';
184
 
184
 
185
+export type AndroidLayerType = 'none' | 'software' | 'hardware';
186
+
185
 export interface WebViewSourceUri {
187
 export interface WebViewSourceUri {
186
   /**
188
   /**
187
    * The URI to load in the `WebView`. Can be a local or remote file.
189
    * The URI to load in the `WebView`. Can be a local or remote file.
284
   allowFileAccessFromFileURLs?: boolean;
286
   allowFileAccessFromFileURLs?: boolean;
285
   allowUniversalAccessFromFileURLs?: boolean;
287
   allowUniversalAccessFromFileURLs?: boolean;
286
   androidHardwareAccelerationDisabled?: boolean;
288
   androidHardwareAccelerationDisabled?: boolean;
289
+  androidLayerType?: AndroidLayerType;
287
   domStorageEnabled?: boolean;
290
   domStorageEnabled?: boolean;
288
   geolocationEnabled?: boolean;
291
   geolocationEnabled?: boolean;
289
   javaScriptEnabled?: boolean;
292
   javaScriptEnabled?: boolean;
809
    */
812
    */
810
   androidHardwareAccelerationDisabled?: boolean;
813
   androidHardwareAccelerationDisabled?: boolean;
811
 
814
 
815
+    /**
816
+   * https://developer.android.com/reference/android/webkit/WebView#setLayerType(int,%20android.graphics.Paint)
817
+   * Sets the layerType. Possible values are:
818
+   *
819
+   * - `'none'` (default)
820
+   * - `'software'`
821
+   * - `'hardware'`
822
+   *
823
+   * @platform android
824
+   */
825
+  androidLayerType?: AndroidLayerType;
826
+
812
   /**
827
   /**
813
    * Boolean value to enable third party cookies in the `WebView`. Used on
828
    * Boolean value to enable third party cookies in the `WebView`. Used on
814
    * Android Lollipop and above only as third party cookies are enabled by
829
    * Android Lollipop and above only as third party cookies are enabled by