Skip to content

When returning to the main screen with the physical back button, it does not return from the directed screen #12748

@nexquery

Description

@nexquery

Current behavior

While on the Home screen, I go to the Settings screen. When I return to the Home screen with the physical back button, there's no problem. However, when I press the physical back button again while on the Home screen, it takes me back to the phone's home screen and the app is put in the background. When I open the app again, the Home screen opens. If I press the physical back button while on the Settings screen, the app is put in the background again.

import { Text, View, TouchableOpacity } from "react-native";
import { SafeAreaProvider } from "react-native-safe-area-context";
import { NativeStackScreenProps } from "@react-navigation/native-stack";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import { NavigationContainer } from "@react-navigation/native";

export type RootStackParamList = {
    Home: undefined;
    Settings: undefined;
};

export type StackScreenProps<RouteName extends keyof RootStackParamList> = NativeStackScreenProps<RootStackParamList, RouteName>;

const RootStack = createNativeStackNavigator<RootStackParamList>();

export default function App() {
    return (
        <SafeAreaProvider>
            <NavigationContainer>
                <RootStack.Navigator screenOptions={{ headerShown: false, animation: 'fade' }}>
                    <RootStack.Screen name="Home" component={Screen_Home} options={{ statusBarStyle: 'dark', statusBarTranslucent: true }} />
                    <RootStack.Screen name="Settings" component={Screen_Settings} options={{ statusBarStyle: 'dark', statusBarTranslucent: true }} />
                </RootStack.Navigator>
            </NavigationContainer>
        </SafeAreaProvider>

    );
}

export function Screen_Home({ navigation, route }: StackScreenProps<'Home'>)
{
    const goSettings = () => {
        console.log("goSettings");
        navigation.navigate('Settings');
    }

    return (
        <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
            <Text>Home</Text>
            
            <TouchableOpacity activeOpacity={0.7} style={{ padding: 10, backgroundColor: 'black', borderRadius: 8, marginTop: 20 }} onPress={goSettings}>
                <Text style={{ fontWeight: 'bold', color: 'white' }}>Settings</Text>
            </TouchableOpacity>
        </View>
    )
}

export function Screen_Settings({ navigation, route }: StackScreenProps<'Settings'>)
{
    return (
        <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
            <Text>Settings</Text>
        </View>
    )
}
2025-09-09.22-39-31.mp4

Expected behavior

When I press the physical back button while on the Home screen, the app goes to the background. When I re-enter the app and go to Settings, pressing the physical back button should take me back to the Home screen.

Reproduction

Hopefully the issue is clear enough, that this is not needed.

Platform

  • Android
  • iOS
  • Web
  • Windows
  • MacOS

Packages

  • @react-navigation/bottom-tabs
  • @react-navigation/drawer
  • @react-navigation/material-top-tabs
  • @react-navigation/stack
  • @react-navigation/native-stack
  • react-native-drawer-layout
  • react-native-tab-view

Environment

  • [] I've removed the packages that I don't use
package version
@react-navigation/native ^7.1.17
@react-navigation/native-stack ^7.3.26
react-native-screens ^4.16.0
react-native-safe-area-context ^5.6.1
react-native-gesture-handler ^2.28.0
react-native-reanimated ^4.1.0
react-native 0.81.1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions