I'm migrating a RN project version 4 to 5.
When switching screens there was an issue with a white background flashing in. In v4 this was solved by setting cardStyle: { backgroundColor: material.containerBgColor }
in the StackNavigation
options.
However in v5 I'm unable to fix it with the same approach:
<Stack.Navigator cardStyle={{ backgroundColor: material.containerBgColor }} ...>
White flash has come back. Any idea how to fix it? Thanks.
Update: The structure of the navigation may be important:
const AppTabNavigator = () => ( <Tab.Navigator> <Tab.Screen name="Home" component={Home} /> <Stack.Screen name="ScreenD" component={ScreenD} /> <Stack.Screen name="ScreenE" component={ScreenE} /> <Stack.Screen name="ScreenF" component={ScreenF} /> </Tab.Navigator> ) ... <Stack.Navigator ... cardStyle={{ backgroundColor: material.containerBgColor }} > <Stack.Screen name="Home" component={AppTabNavigator} /> <Stack.Screen name="ScreenA" component={ScreenA} /> <Stack.Screen name="ScreenB" component={ScreenB} /> <Stack.Screen name="ScreenC" component={ScreenC} /> </Stack.Navigator>
Going from ScreenD to ScreenE does the flashing issue. I'm not sure about the other screens as they don't make any network request / async stuff.
To make this work, you need to: Disable the swipe gesture for the screen ( gestureEnabled: false ). Override the native back button in the header with a custom back button ( headerLeft: (props) => <CustomBackButton {... props} /> ).
Integration with existing apps In such a case, any navigator based on JS works well compared to existing native solutions. This gives React Navigation the edge over RNN, especially if you are looking to power a few modules of your existing app with React Native, just like Facebook and many other brownfield apps do.
React Navigation related packages include @react-navigation/drawer , @react-navigation/stack , @react-navigation/bottom-tabs and @react-navigation/material-top-tabs use react-native-gesture-handler and react-native-reanimated for smooth gestures and animations.
React Navigation's web support currently requires using React Native for Web. This approach lets us reuse the same code on both React Native and Web.
I faced the same issue and dived into an investigation. It seems that the detachment of the screens causes it. I found a few approaches. You can choose one according to your needs. They are the following:
You can specify a view wrapper of the navigator with the same background color as the screens one like:
<View style={{ flex: 1, backgroundColor: '#YOUR_SCREEN_COLOR' }}> // It could be your NavigationContainer or your StackNavigator depends on your goals <Navigator /> </View>
You can also specify your screen mode to be modal
in the stack view config this prevents the screens from being detached like:
<StackNavigator.Navigator mode="modal"> {/*.... Your stack screens ... */} </StackNavigator.Navigator>
You can add your custom overlay in screenOptions
by using the cardOverlay
prop:
cardOverlay: () => ( <View style={{ flex: 1, backgroundColor: '#YOUR_COLOR', }} />)
Reference: https://reactnavigation.org/docs/stack-navigator/#cardoverlay
You can use the cardStyleInterpolator
:
This allows you to customize the animation transitions when navigating from screen to screen.
Here are the snippets from the original documentation:
const forFade = ({ current, closing }) => ({ cardStyle: { opacity: current.progress, }, });
<Stack.Screen name="Profile" component={Profile} options={{ cardStyleInterpolator: forFade }} />
Stack Navigator exposes various options to configure the transition animation when a screen is added or removed.
Reference: https://reactnavigation.org/docs/stack-navigator/#animation-related-options
Fixed it by using the DarkTheme for the Navigation Container
import { NavigationContainer, DarkTheme } from '@react-navigation/native'; return ( <NavigationContainer theme={DarkTheme}> {children} </NavigationContainer>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With