Bläddra i källkod

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 6 år sedan
förälder
incheckning
d3fc5e6cde

+ 7
- 0
android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java Visa fil

@@ -529,6 +529,13 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
529 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 539
   @ReactProp(name = "overScrollMode")
533 540
   public void setOverScrollMode(WebView view, String overScrollModeString) {
534 541
     Integer overScrollMode;

+ 11
- 0
docs/Reference.md Visa fil

@@ -28,6 +28,7 @@ This document lays out the current public properties and methods for the React N
28 28
 - [`decelerationRate`](Reference.md#decelerationrate)
29 29
 - [`domStorageEnabled`](Reference.md#domstorageenabled)
30 30
 - [`javaScriptEnabled`](Reference.md#javascriptenabled)
31
+- [`androidHardwareAccelerationDisabled`](Reference.md#androidHardwareAccelerationDisabled)
31 32
 - [`mixedContentMode`](Reference.md#mixedcontentmode)
32 33
 - [`thirdPartyCookiesEnabled`](Reference.md#thirdpartycookiesenabled)
33 34
 - [`userAgent`](Reference.md#useragent)
@@ -319,6 +320,16 @@ Boolean value to enable JavaScript in the `WebView`. Used on Android only as Jav
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 333
 ### `mixedContentMode`
323 334
 
324 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 Visa fil

@@ -67,6 +67,7 @@ class WebView extends React.Component<WebViewSharedProps, State> {
67 67
     scalesPageToFit: true,
68 68
     allowFileAccess: false,
69 69
     saveFormDataDisabled: false,
70
+    androidHardwareAccelerationDisabled: false,
70 71
     originWhitelist: defaultOriginWhitelist,
71 72
   };
72 73
 
@@ -150,6 +151,7 @@ class WebView extends React.Component<WebViewSharedProps, State> {
150 151
         injectedJavaScript={this.props.injectedJavaScript}
151 152
         userAgent={this.props.userAgent}
152 153
         javaScriptEnabled={this.props.javaScriptEnabled}
154
+        androidHardwareAccelerationDisabled={this.props.androidHardwareAccelerationDisabled}
153 155
         thirdPartyCookiesEnabled={this.props.thirdPartyCookiesEnabled}
154 156
         domStorageEnabled={this.props.domStorageEnabled}
155 157
         messagingEnabled={typeof this.props.onMessage === 'function'}

+ 7
- 0
js/WebViewTypes.js Visa fil

@@ -313,6 +313,13 @@ export type AndroidWebViewProps = $ReadOnly<{|
313 313
    */
314 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 324
    * Boolean value to enable third party cookies in the `WebView`. Used on
318 325
    * Android Lollipop and above only as third party cookies are enabled by

+ 7
- 0
typings/index.d.ts Visa fil

@@ -287,6 +287,13 @@ export interface AndroidWebViewProps {
287 287
    */
288 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 298
    * Boolean value to enable third party cookies in the `WebView`. Used on
292 299
    * Android Lollipop and above only as third party cookies are enabled by