Browse Source

feat(android props): Add `androidHardwareAccelerationDisabled` prop (#265)

* add test code for disable hardware acceleration

* add interface to disable android hardware acceleration

* Update index.d.ts
Margaret 5 years ago
parent
commit
d3fc5e6cde

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

529
     view.getSettings().setJavaScriptEnabled(enabled);
529
     view.getSettings().setJavaScriptEnabled(enabled);
530
   }
530
   }
531
 
531
 
532
+  @ReactProp(name = "androidHardwareAccelerationDisabled")
533
+  public void setHardwareAccelerationDisabled(WebView view, boolean disabled) {
534
+    if (disabled) {
535
+      view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
536
+    }
537
+  }
538
+
532
   @ReactProp(name = "overScrollMode")
539
   @ReactProp(name = "overScrollMode")
533
   public void setOverScrollMode(WebView view, String overScrollModeString) {
540
   public void setOverScrollMode(WebView view, String overScrollModeString) {
534
     Integer overScrollMode;
541
     Integer overScrollMode;

+ 11
- 0
docs/Reference.md View File

28
 - [`decelerationRate`](Reference.md#decelerationrate)
28
 - [`decelerationRate`](Reference.md#decelerationrate)
29
 - [`domStorageEnabled`](Reference.md#domstorageenabled)
29
 - [`domStorageEnabled`](Reference.md#domstorageenabled)
30
 - [`javaScriptEnabled`](Reference.md#javascriptenabled)
30
 - [`javaScriptEnabled`](Reference.md#javascriptenabled)
31
+- [`androidHardwareAccelerationDisabled`](Reference.md#androidHardwareAccelerationDisabled)
31
 - [`mixedContentMode`](Reference.md#mixedcontentmode)
32
 - [`mixedContentMode`](Reference.md#mixedcontentmode)
32
 - [`thirdPartyCookiesEnabled`](Reference.md#thirdpartycookiesenabled)
33
 - [`thirdPartyCookiesEnabled`](Reference.md#thirdpartycookiesenabled)
33
 - [`userAgent`](Reference.md#useragent)
34
 - [`userAgent`](Reference.md#useragent)
319
 
320
 
320
 ---
321
 ---
321
 
322
 
323
+### `androidHardwareAccelerationDisabled`
324
+
325
+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`.
326
+
327
+| Type | Required | Platform |
328
+| ---- | -------- | -------- |
329
+| bool | No       | Android  |
330
+
331
+---
332
+
322
 ### `mixedContentMode`
333
 ### `mixedContentMode`
323
 
334
 
324
 Specifies the mixed content mode. i.e WebView will allow a secure origin to load content from any other origin.
335
 Specifies the mixed content mode. i.e WebView will allow a secure origin to load content from any other origin.

+ 2
- 0
js/WebView.android.js View File

67
     scalesPageToFit: true,
67
     scalesPageToFit: true,
68
     allowFileAccess: false,
68
     allowFileAccess: false,
69
     saveFormDataDisabled: false,
69
     saveFormDataDisabled: false,
70
+    androidHardwareAccelerationDisabled: false,
70
     originWhitelist: defaultOriginWhitelist,
71
     originWhitelist: defaultOriginWhitelist,
71
   };
72
   };
72
 
73
 
150
         injectedJavaScript={this.props.injectedJavaScript}
151
         injectedJavaScript={this.props.injectedJavaScript}
151
         userAgent={this.props.userAgent}
152
         userAgent={this.props.userAgent}
152
         javaScriptEnabled={this.props.javaScriptEnabled}
153
         javaScriptEnabled={this.props.javaScriptEnabled}
154
+        androidHardwareAccelerationDisabled={this.props.androidHardwareAccelerationDisabled}
153
         thirdPartyCookiesEnabled={this.props.thirdPartyCookiesEnabled}
155
         thirdPartyCookiesEnabled={this.props.thirdPartyCookiesEnabled}
154
         domStorageEnabled={this.props.domStorageEnabled}
156
         domStorageEnabled={this.props.domStorageEnabled}
155
         messagingEnabled={typeof this.props.onMessage === 'function'}
157
         messagingEnabled={typeof this.props.onMessage === 'function'}

+ 7
- 0
js/WebViewTypes.js View File

313
    */
313
    */
314
   javaScriptEnabled?: ?boolean,
314
   javaScriptEnabled?: ?boolean,
315
 
315
 
316
+  /**
317
+   * Boolean value to disable Hardware Acceleration in the `WebView`. Used on Android only
318
+   * as Hardware Acceleration is a feature only for Android. The default value is `false`.
319
+   * @platform android
320
+   */
321
+  androidHardwareAccelerationDisabled?: ?boolean,
322
+
316
   /**
323
   /**
317
    * Boolean value to enable third party cookies in the `WebView`. Used on
324
    * Boolean value to enable third party cookies in the `WebView`. Used on
318
    * Android Lollipop and above only as third party cookies are enabled by
325
    * Android Lollipop and above only as third party cookies are enabled by

+ 7
- 0
typings/index.d.ts View File

287
    */
287
    */
288
   javaScriptEnabled?: boolean;
288
   javaScriptEnabled?: boolean;
289
 
289
 
290
+  /**
291
+   * Boolean value to disable Hardware Acceleration in the `WebView`. Used on Android only
292
+   * as Hardware Acceleration is a feature only for Android. The default value is `false`.
293
+   * @platform android
294
+   */
295
+  androidHardwareAccelerationDisabled?: boolean;
296
+
290
   /**
297
   /**
291
    * Boolean value to enable third party cookies in the `WebView`. Used on
298
    * Boolean value to enable third party cookies in the `WebView`. Used on
292
    * Android Lollipop and above only as third party cookies are enabled by
299
    * Android Lollipop and above only as third party cookies are enabled by