Webview导致react-native应用在导航时崩溃



这个应用程序在我测试的多个Android设备上都崩溃了。当我从欢迎屏幕转到一个只有webview标签的屏幕时,我点击返回欢迎屏幕并点击登录按钮,该按钮有登录成功的导航代码,这里它在导航前崩溃:

const resetAction = CommonActions.reset({
index: 1,
routes: [{ name: 'primaryStack' }]
})
function login() {
.....
.....
if (success) navigation.dispatch(resetAction)
}

这是我在webview屏幕上的webview标签:

<WebView
// style={{ opacity: 0.99, overflow: 'hidden' }}
source={{ uri: 'http://192.168.1.6:8000/admin' }}
androidHardwareAccelerationDisabled
startInLoadingState={true}
renderLoading={() => 
<Text style={[P,{color:color.palette.blue,alignSelf:"center",}]}
numberOfLines={1} ellipsizeMode="tail">
Loading…
</Text>
}
/>
</View>

我的导航堆栈:

<NavigationContainer {...props} ref={ref}>
<Stack.Navigator
screenOptions={{
headerShown: false,
gestureEnabled: true,
}}
>

{ (rootStore.auth.loggedin) ?
<Stack.Screen
name="primaryStack"
component={PrimaryNavigator}
options={{
headerShown: false,
screenOrientation: "portrait",
}}
/> :
<Stack.Screen
name="authStack"
component={AuthNavigator}
options={{
headerShown: false,
screenOrientation: "portrait",
}}
/>
}

</Stack.Navigator>
</NavigationContainer>

包:

...
...
"@react-navigation/native": "^5.1.5",
"mobx": "^4.15.4",
"mobx-react-lite": "^1.4.1",
"mobx-state-tree": "^3.14.1",
"react-native-safe-area-view": "1.1.1",
"react-native-screens": "^2.10.1",
"react-native-webview": "^11.13.0",
...
...

你见过WebView在导航时崩溃的画面吗?

解决方案:<Stack.Screen ... options={{animationEnabled: false}} />react-navigation >= 6.x use <Stack.Screen ... options={{animation:'none'}} />

我想可能是react-Navigation库和webView库之间存在冲突。在元件中采用opacity = 0.99解决了这一问题。所以如果你删除了那一行的注释,问题就解决了。

最新更新