react-native从含有Webview的页面后退造成app崩溃

1.问题描述;

从含有webview的页面后退时出现了app崩溃,并且并无报错。

2.版本:

1
2
3
4
"react""16.11.0",
"react-native""0.62.2",
"react-native-screens""^2.10.1",
"react-native-webview""^10.3.2",

3.造成这种原因的大多说法是 "react-native-screens"和"react-native-webview"冲突。以下是各个关于这个说法的网站链接:

react-navigation:https://github.com/react-navigation/react-navigation/issues/8099

https://github.com/react-navigation/react-navigation/issues/6960

文中提到的解决方案有:

在WebView上进行设置androidHardwareAccelerationDisabled    (原文地址:https://github.com/software-mansion/react-native-screens/issues/214)

 <WebView
            //style={{ opacity: 0.99}}
            androidHardwareAccelerationDisabled
            source={{ html: "<h1 style='font-size: 50px'>Webview: Hello world!</h1>" }}
          />

问题产生原因:

在 Screen.java中

public void setTransitioning(boolean transitioning) {
    if (mTransitioning == transitioning) {
      return;
    }
    mTransitioning = transitioning;
    super.setLayerType(transitioning ? View.LAYER_TYPE_HARDWARE : View.LAYER_TYPE_NONE, null);
  }

4.最后解决的方式是:

我原在app.js中引入了

import { enableScreens } from 'react-native-screens';

enableScreens(); 

现在把它删了,然后页面返回不会再有崩溃

原文地址:https://www.cnblogs.com/dsweb/p/13447744.html