Webview causing react-native app to crash on navigation

Viewed 1518

The app crashes on multiple Android devices I tested on. When I go from the welcome screen to a screen containing nothing but the webview tag, I click back to welcome screen and hit login button that has this navigation code on login success, here it crashes before the navigation:

const resetAction = CommonActions.reset({
  index: 1,
  routes: [{ name: 'primaryStack' }]
 })

function login() {
 .....
 .....
 if (success) navigation.dispatch(resetAction)
}

Here's my webview tag on the webview screen:

       <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>

My navigation stacks:

<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>

Packages:

...
...
"@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",
...
...
2 Answers

i think maybe there is conflict between react-Navigation lib and webView lib. i solved that problem by using opacity = 0.99 in component. so if you delete your comment out at that line, that will be solved.

Related