From d3fc5e6cde979e865a776977331efa349c2a067f Mon Sep 17 00:00:00 2001 From: Margaret Date: Tue, 22 Jan 2019 17:21:10 +0800 Subject: [PATCH] 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 --- .../webview/RNCWebViewManager.java | 7 +++++++ docs/Reference.md | 11 +++++++++++ js/WebView.android.js | 2 ++ js/WebViewTypes.js | 7 +++++++ typings/index.d.ts | 7 +++++++ 5 files changed, 34 insertions(+) diff --git a/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java b/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java index c1c3163..663416c 100644 --- a/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java +++ b/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java @@ -529,6 +529,13 @@ public class RNCWebViewManager extends SimpleViewManager { view.getSettings().setJavaScriptEnabled(enabled); } + @ReactProp(name = "androidHardwareAccelerationDisabled") + public void setHardwareAccelerationDisabled(WebView view, boolean disabled) { + if (disabled) { + view.setLayerType(View.LAYER_TYPE_SOFTWARE, null); + } + } + @ReactProp(name = "overScrollMode") public void setOverScrollMode(WebView view, String overScrollModeString) { Integer overScrollMode; diff --git a/docs/Reference.md b/docs/Reference.md index f1f1bc2..c829232 100644 --- a/docs/Reference.md +++ b/docs/Reference.md @@ -28,6 +28,7 @@ This document lays out the current public properties and methods for the React N - [`decelerationRate`](Reference.md#decelerationrate) - [`domStorageEnabled`](Reference.md#domstorageenabled) - [`javaScriptEnabled`](Reference.md#javascriptenabled) +- [`androidHardwareAccelerationDisabled`](Reference.md#androidHardwareAccelerationDisabled) - [`mixedContentMode`](Reference.md#mixedcontentmode) - [`thirdPartyCookiesEnabled`](Reference.md#thirdpartycookiesenabled) - [`userAgent`](Reference.md#useragent) @@ -319,6 +320,16 @@ Boolean value to enable JavaScript in the `WebView`. Used on Android only as Jav --- +### `androidHardwareAccelerationDisabled` + +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`. + +| Type | Required | Platform | +| ---- | -------- | -------- | +| bool | No | Android | + +--- + ### `mixedContentMode` Specifies the mixed content mode. i.e WebView will allow a secure origin to load content from any other origin. diff --git a/js/WebView.android.js b/js/WebView.android.js index 3e6aefd..cd30afa 100644 --- a/js/WebView.android.js +++ b/js/WebView.android.js @@ -67,6 +67,7 @@ class WebView extends React.Component { scalesPageToFit: true, allowFileAccess: false, saveFormDataDisabled: false, + androidHardwareAccelerationDisabled: false, originWhitelist: defaultOriginWhitelist, }; @@ -150,6 +151,7 @@ class WebView extends React.Component { injectedJavaScript={this.props.injectedJavaScript} userAgent={this.props.userAgent} javaScriptEnabled={this.props.javaScriptEnabled} + androidHardwareAccelerationDisabled={this.props.androidHardwareAccelerationDisabled} thirdPartyCookiesEnabled={this.props.thirdPartyCookiesEnabled} domStorageEnabled={this.props.domStorageEnabled} messagingEnabled={typeof this.props.onMessage === 'function'} diff --git a/js/WebViewTypes.js b/js/WebViewTypes.js index 46ca05e..eb672d0 100644 --- a/js/WebViewTypes.js +++ b/js/WebViewTypes.js @@ -313,6 +313,13 @@ export type AndroidWebViewProps = $ReadOnly<{| */ javaScriptEnabled?: ?boolean, + /** + * 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`. + * @platform android + */ + androidHardwareAccelerationDisabled?: ?boolean, + /** * Boolean value to enable third party cookies in the `WebView`. Used on * Android Lollipop and above only as third party cookies are enabled by diff --git a/typings/index.d.ts b/typings/index.d.ts index 4fa7640..39ea30a 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -287,6 +287,13 @@ export interface AndroidWebViewProps { */ javaScriptEnabled?: boolean; + /** + * 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`. + * @platform android + */ + androidHardwareAccelerationDisabled?: boolean; + /** * Boolean value to enable third party cookies in the `WebView`. Used on * Android Lollipop and above only as third party cookies are enabled by