fix(Android): hardware acceleration issue (#854)

* Fix https://github.com/react-native-community/react-native-webview/issues/575

* Check if hardware acceleration is available also

* Alternative way to check isHarewareAccelerated
This commit is contained in:
thanakij 2019-09-23 05:03:42 +07:00 committed by Thibault Malbranche
parent a2440f0491
commit 9e25e42cee
1 changed files with 5 additions and 2 deletions

View File

@ -259,10 +259,13 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
@ReactProp(name = "androidHardwareAccelerationDisabled") @ReactProp(name = "androidHardwareAccelerationDisabled")
public void setHardwareAccelerationDisabled(WebView view, boolean disabled) { public void setHardwareAccelerationDisabled(WebView view, boolean disabled) {
if (disabled) { ReactContext reactContext = (ReactContext) view.getContext();
final boolean isHardwareAccelerated = (reactContext.getCurrentActivity().getWindow()
.getAttributes().flags & WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
if (disabled || !isHardwareAccelerated) {
view.setLayerType(View.LAYER_TYPE_SOFTWARE, null); view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
} else { } else {
view.setLayerType(View.LAYER_TYPE_NONE, null); view.setLayerType(View.LAYER_TYPE_HARDWARE, null);
} }
} }