Skip to content

Commit

Permalink
feat(android props): Add androidHardwareAccelerationDisabled prop (#…
Browse files Browse the repository at this point in the history
…265)

* add test code for disable hardware acceleration

* add interface to disable android hardware acceleration

* Update index.d.ts
  • Loading branch information
YangXiaomei authored and Titozzz committed Jan 22, 2019
1 parent 05f2086 commit d3fc5e6
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,13 @@ public void setJavaScriptEnabled(WebView view, boolean enabled) {
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;
Expand Down
11 changes: 11 additions & 0 deletions docs/Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions js/WebView.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class WebView extends React.Component<WebViewSharedProps, State> {
scalesPageToFit: true,
allowFileAccess: false,
saveFormDataDisabled: false,
androidHardwareAccelerationDisabled: false,
originWhitelist: defaultOriginWhitelist,
};

Expand Down Expand Up @@ -150,6 +151,7 @@ class WebView extends React.Component<WebViewSharedProps, State> {
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'}
Expand Down
7 changes: 7 additions & 0 deletions js/WebViewTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d3fc5e6

Please sign in to comment.