New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
White screen on transition while using "Protected routes" #10894
Comments
Any updates on this? |
mini solution) |
@tegozen thanks for the suggestion. I tested it here and it doesn't solve the initial issue. And, in using the presentation mode of a Modal, it would change the animations of my navigation flow, deviating from the original animations users are used for iOS for normal screen transitions. |
I'm having the same issue with the native stack and RN v0.70.6, has anyone found a solution? |
btw. here the issue in the react-native-screens repo: software-mansion/react-native-screens#1628 So, in the meanwhile a workaround is to use plain React Native Views by disabling react-native-screens: https://github.com/software-mansion/react-native-screens#disabling-react-native-screens |
just ran into this issue on Android 10 devices using a NativeStackNavigator. I was able to work around the blank screen issue by moving the conditional rendering outside of the render and setting a key on the navigator to force a refresh. previously: const App = () => {
const {currentUser} = useAuthListener(); // custom hook that listens for changes to auth.
return (
<View style={styles.container}>
<RootStack.Navigator>
{currentUser ? (
<RootStack.Screen
name={RootStackRoutes.Home}
component={HomeScreen}
/>
) : (
<RootStack.Screen
name={RootStackRoutes.Auth}
component={AuthScreen}
/>
)
}
</RootStack.Navigator>
</View>
);
}; working code: const App = () => {
const {currentUser} = useAuthListener(); // custom hook that listens for changes to auth.
if (currentUser) {
return (
<View style={styles.container}>
<RootStack.Navigator key="has_current_user">
<RootStack.Screen
name={RootStackRoutes.Home}
component={HomeScreen}
/>
</RootStack.Navigator>
</View>
);
};
return (
<View style={styles.container}>
<RootStack.Navigator key="no_current_user">
<RootStack.Screen
name={RootStackRoutes.Auth}
component={AuthScreen}
/>
</RootStack.Navigator>
</View>
);
}; |
@skam22 const App = () => {
const {currentUser} = useAuthListener(); // custom hook that listens for changes to auth.
return (
<View style={styles.container}>
<RootStack.Navigator key={currentUser ? "has_current_user" : "no_current_user"}>
{currentUser ? (
<RootStack.Screen
name={RootStackRoutes.Home}
component={HomeScreen}
/>
) : (
<RootStack.Screen
name={RootStackRoutes.Auth}
component={AuthScreen}
/>
)
}
</RootStack.Navigator>
</View>
);
}; |
I fixed this by delaying my async hook by a few mili seconds with Here is an example: export const AppNavigation = () => {
const { authDispatch } = useAuthContext();
React.useEffect(() => {
const bootstrapAsync = async () => {
try {
await new Promise((res) => setTimeout(res, 500)); // allows react navigation to render the screen for transition
const user = await someAuthFunction();
authDispatch(
authActions.restoreToken(user),
);
} catch (e) {
// Failed to get token ensure user is signed out
authDispatch(authActions.signOut());
}
};
bootstrapAsync();
}, [authDispatch]);
return (
<NavigationContainer fallback={<LoadingScreen />} />
<RootStackNavigator />
</NavigationContainer>
);
};
const App = () => {
const { authState } = useAuthContext(); // custom hook that listens for changes to auth.
const { isLoggedIn } = authState;
return (
<AppNavigation >
<RootStack.Navigator>
{isLoggedIn ? (
<RootStack.Screen
name={RootStackRoutes.Home}
component={HomeScreen}
/>
) : (
<RootStack.Screen
name={RootStackRoutes.Auth}
component={AuthScreen}
/>
)
}
</RootStack.Navigator>
</AppNavigation>
);
}; |
Current behavior
I have an authentication flow pretty similar to the one described in the documentation. A loading screen, an authentication flow and an authenticated flow.
While using RN 0.67, @react-navigation/native 6.0.8, @react-navigation/native-stack 6.5.2, the implementation was working properly, with the screens being transitioned as needed, as it would be expected.
But now I started to migrate my project to the latest version of RN, 0.70.1, enabling both Hermes and Fabric, and the same flow doesn't work anymore. The first screen will show as expected, but when the flag changes and the navigation is supposed to transition to the new screen, the app just gets blank, no visible error or crash.
Navigation is working properly. If I don't use the Protected routes pattern, I can normally navigate back and forth between the screens of my flow, but using the Pattern doesn't work.
The following code is pretty similar to what I have in my real app, and it behaves the same way, with a white screen. (The provided repo is basically this code with all the configuration I have in a testing project)
The "Blue" screen will show as expected, and when 1s passes, the screen gets blank and "Blue" is still the name of the navigation, but the "Red" screen never shows, as you can see in the video:
Simulator.Screen.Recording.-.iPhone.14.-.2022-09-29.at.19.10.35.mp4
Worth mentioning that I'm using a M1 Macbook, since RN had issues with it in the past, but I think it's not related.
Expected behavior
While using the Protected routes pattern, when the controlling flag changes, the navigation stack should transition between the screens provided, instead of showing a white screen.
Reproduction
https://github.com/leobHumi/ReactNavigationBug
Platform
Packages
Environment
The text was updated successfully, but these errors were encountered: