react-native-webview 在 Android 上闪退问题解决

文章目录[隐藏]

在 React Native 中引入 react-native-webview 之后,多次打开关闭,会出现闪退的情况
新开 WebView 是通过react-navigation 的方式

解决办法是:

  1. 设置 Webivew 的不透明度为 0.99
<WebView
source={source}
webViewStyle={{ opacity: 0.99 }}
/>
  1. 关闭导航动画
navigationOptions: { animationEnabled: false }

可以这么做, 同时可以在导航条上设置一下 title

const handleNavigationStateChange = (navState) => {
       setProgress(navState.loading ? navState.progress : 1);
       
       // Check if the provided URL is invalid
       if (!isValidURL(navState.url)) {
           navigation.setOptions({ title: '无效的 url' });
       } else if (navState.title) {
           navigation.setOptions({ title: navState.title, animationEnabled: false });
       }
   };

<WebView
source={source}
webViewStyle={{ opacity: 0.99 }}
onNavigationStateChange={handleNavigationStateChange}
/>

参考文档

WebView recently started crashing on Android on some devices · Issue #430 · react-native-webview/react-native-webview · GitHub


已发布

分类

作者:

标签

评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注