react-navigation icon indicating copy to clipboard operation
react-navigation copied to clipboard

Android: Blank screen is displayed after modal navigation

Open RuntimeSyntax opened this issue 6 years ago • 15 comments

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 Details screen
  • Then you see a blank screen instead of Details screen

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

RuntimeSyntax avatar Dec 17 '19 14:12 RuntimeSyntax

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.

CoSNaYe avatar Jan 06 '20 08:01 CoSNaYe

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.

RuntimeSyntax avatar Jan 06 '20 19:01 RuntimeSyntax

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!

xeruf avatar Jan 20 '20 15:01 xeruf

@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() ?

RuntimeSyntax avatar Jan 22 '20 15:01 RuntimeSyntax

how would I remove that? For now I fixed it by going back to React Navigation 3...

xeruf avatar Jan 23 '20 11:01 xeruf

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)

miguelSWE avatar Jan 23 '20 19:01 miguelSWE

Experiencing the same issue here. Any tips to fix it?

SandroMachado avatar Mar 03 '20 00:03 SandroMachado

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.

github-actions[bot] avatar Mar 20 '20 13:03 github-actions[bot]

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.

h1st0ry3D avatar Mar 24 '20 12:03 h1st0ry3D

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

outaTiME avatar Apr 06 '20 06:04 outaTiME

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

AyeshaIftikharr avatar Apr 13 '20 21:04 AyeshaIftikharr

Closing since this seems to be fixed in screens

satya164 avatar Apr 23 '20 12:04 satya164

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.

alexleone avatar Nov 05 '20 20:11 alexleone

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.

TheMahadee avatar Apr 15 '25 10:04 TheMahadee

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.

github-actions[bot] avatar Apr 15 '25 10:04 github-actions[bot]