Android: Blank screen is displayed after modal navigation
Current Behavior
On Android, a blank screen is displayed when I navigate to a screen after a modal.
Expected Behavior
On Android, I should can navigate between modal and screen.
How to reproduce
- Copy paste example below in a React Native app.js
- Navigate to
Modal - Then navigate back
- Then navigate to
Detailsscreen - Then you see a blank screen instead of
Detailsscreen
Note: Details screen is displayed correctly if you do not navigate to modal before.
import React from "react";
import { Button, Text, View } from "react-native";
import RNBootSplash from "react-native-bootsplash";
import { createAppContainer } from "react-navigation";
class HomeScreen extends React.Component {
render() {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>Home</Text>
<Button
title="Go to Details"
onPress={() => {
this.props.navigation.navigate('Details');
}}
/>
<Button
title="Go to Modal"
onPress={() => {
this.props.navigation.navigate('Modal');
}}
/>
</View>
);
}
}
class DetailsScreen extends React.Component {
render() {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>Details</Text>
<Button
title="Go back"
onPress={() => this.props.navigation.goBack()}
/>
</View>
);
}
}
class ModalScreen extends React.Component {
render() {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>Modal</Text>
<Button
onPress={() => this.props.navigation.goBack()}
title="Go back"
/>
</View>
);
}
}
const MainStack = createStackNavigator(
{
Home: {
screen: HomeScreen,
},
Details: {
screen: DetailsScreen,
},
},
{
initialRouteName: 'Home'
}
);
const RootStack = createStackNavigator(
{
Main: {
screen: MainStack,
},
Modal: {
screen: ModalScreen,
},
},
{
mode: 'modal',
headerMode: 'none',
}
);
const AppContainer = createAppContainer(RootStack);
export default class App extends React.Component {
render() {
return <AppContainer />;
}
}
Environment
| software | version |
|---|---|
| react-navigation | 4.0.10 |
| react-navigation-drawer | 2.3.3 |
| react-navigation-stack | 1.10.3 |
| react-native-reanimated | 1.4.0 |
| react-native-screens | 2.0.0-alpha.17 |
| react-native-gesture-handler | 1.5.2 |
| react-native | 0.61.5 |
| node | 11.1.0 |
| npm or yarn | 6.4.1 |
| Android | 9.0 API 28 |
I get the same issue as well.
The react-native-screens seems to be the culprit. After removing useScreens() call, the issue has gone.
https://github.com/kmagiera/react-native-screens/issues/238
To who needs a quick workaround. I temporarily downgrade the react-native-screens to 1.0.0-alpha.23 as https://github.com/kmagiera/react-native-screens/issues/238#issuecomment-566561980 states. It works now.
Hello @CoSNaYe
Thank you very much for your feedback! I will try the same workaround until a real fix and I let you know if it works.
I am seeing this same issue, even without using Modals. It works locally via expo, but I get the blank screen when using the apk. Tried react-native-screens 1.0.0-alpha.23, 2.0.0-alpha12 and 2.0.0-alpha26, neither worked... This is a dealbreaker, I might have to downgrade my whole app again!
@CoSNaYe I confirm that the bug was on [email protected]. I downgraded my app to 1.0.0-alpha.23 and it works.
@Xerus2000 Have you tried to disable react-native-screens by removing useScreens() ?
how would I remove that? For now I fixed it by going back to React Navigation 3...
Just to share that we are not using react-native-screens and that we are seeing this issue on Android with recent devices (e.g. S10 - Android 10)
Experiencing the same issue here. Any tips to fix it?
Hey! Thanks for opening the issue. Can you provide a minimal repro which demonstrates the issue? Posting a snippet of your code in the issue is useful, but it's not usually straightforward to run. A repro will help us debug the issue faster. Please try to keep the repro as small as possible. The easiest way to provide a repro is on snack.expo.io. If it's not possible to repro it on snack.expo.io, then you can also provide the repro in a GitHub repository.
I also have the blank screen issue when navigation with goBack on a specific screen. Downgrading to 1.0.0-alpha.23 fixed it also for me. Tried with all 2.X.0 versions until 2.4.0. But the problem still exists. I am using latest react-navigation v5 with latest stack and bottom-tabs.
Yup same here using Expo 37 with the following dependencies:
react-native-screens: 2.2.0 react-navigation: 4.3.7 react-navigation-stack: 2.3.11
I am also using latest react-navigation v5 with latest stack and bottom-tabs and faced this problem of blank screen while trying to navigate via header back button using navigation.navigate('screenName', params)
I fixed this issue by disabling the animation of screens on android without downgrading any package
<Stack.Navigator
initialRouteName='name'
screenOptions={{
animationEnabled: false, // hack
}}
>
Reference: https://github.com/react-navigation/react-navigation/issues/1805 https://github.com/software-mansion/react-native-screens/issues/238
Closing since this seems to be fixed in screens
If you are on a larger codebase and changing dependencies may not be an option right now. I found this simple hack to work pretty well.
React.useLayoutEffect(() => {
navigation.setOptions({headerTitle: 'Search Results'})
}, [navigation, route])
This is force rerendering the component by resetting the title in the header and it solved my issue.
I am using "react-native-screens": "^4.5.0", "@react-navigation/native": "^7.0.14", "@react-navigation/native-stack": "^7.2.0",
This is my Navigation code.
import {enableScreens} from 'react-native-screens';
// Enable optimized screen handling
enableScreens(false);
export const navigationRef = createNavigationContainerRef();
const Stack = createNativeStackNavigator();
export default function Navigation() {
return (
<NavigationContainer ref={navigationRef}>
<Stack.Navigator screenOptions={{headerShown: false}}>
<Stack.Screen name="Splash" component={Splash} />
<Stack.Screen name="Root" component={Root} />
<Stack.Screen name="Login" component={Login} />
<Stack.Screen name="Signup" component={Signup} />
<Stack.Screen name="ForgotPass" component={ForgotPass} />
<Stack.Screen name="Verification" component={Verification} />
<Stack.Screen name="ChangePass" component={ChangePass} />
<Stack.Screen name="Maintenance" component={Maintenance} />
</Stack.Navigator>
</NavigationContainer>
);
}
Whenever I'm running navigation.replace('Root'), the screen goes blank, and I need to minimize then maximize the app to view the page. Other pages don't have this problem.
Hey! This issue is closed and isn't watched by the core team. You are welcome to discuss the issue with others in this thread, but if you think this issue is still valid and needs to be tracked, please open a new issue with a repro.