Allow to toggle Android WebView HardwareAcceleration from JS

Summary:
This diff exposes a new prop for WebView in Android to disable HardwareAcceleration.
Disabling hardware acceleration is sometimes required to workaround chromium bugs: https://bugs.chromium.org/p/chromium/issues/detail?id=501901

Reviewed By: fkgozali

Differential Revision: D13425243

fbshipit-source-id: e3cd53c72d01f74624b60834496f3cc44076b6b5
This commit is contained in:
David Vacca
2018-12-11 21:28:53 -08:00
committed by Facebook Github Bot
parent aaa4a38fbc
commit d1b90ee9e2
3 changed files with 39 additions and 1 deletions
@@ -16,6 +16,7 @@ import android.graphics.Picture;
import android.net.Uri;
import android.os.Build;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.webkit.ConsoleMessage;
import android.webkit.CookieManager;
@@ -83,6 +84,7 @@ import org.json.JSONObject;
* - canGoBack - boolean, whether there is anything on a history stack to go back
* - canGoForward - boolean, whether it is possible to request GO_FORWARD command
*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@ReactModule(name = ReactWebViewManager.REACT_CLASS)
public class ReactWebViewManager extends SimpleViewManager<WebView> {
@@ -437,10 +439,22 @@ public class ReactWebViewManager extends SimpleViewManager<WebView> {
if (ReactBuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
WebView.setWebContentsDebuggingEnabled(true);
}
return webView;
}
@ReactProp(name = "hardwareAccelerationEnabledExperimental", defaultBoolean = true)
public void sethardwareAccelerationEnabledExperimental(WebView view, boolean enabled) {
// Hardware acceleration can not be enabled at view level but it can be disabled
// see: https://developer.android.com/guide/topics/graphics/hardware-accel
//
// Disabling hardware acceleration is sometimes required to workaround chromium bugs:
// https://bugs.chromium.org/p/chromium/issues/detail?id=501901
//
if (!enabled) {
view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
}
@ReactProp(name = "javaScriptEnabled")
public void setJavaScriptEnabled(WebView view, boolean enabled) {
view.getSettings().setJavaScriptEnabled(enabled);