Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native 如何清除所有抽屉堆栈并注销应用程序窗体_React Native - Fatal编程技术网

React native 如何清除所有抽屉堆栈并注销应用程序窗体

React native 如何清除所有抽屉堆栈并注销应用程序窗体,react-native,React Native,在我的应用程序中,我有一个主堆栈导航器(登录、抽屉)。我在react native中创建了一个抽屉导航器(“react navigation/drawer”:“^5.1.1”)。每个抽屉中都有一个堆栈导航器。那么,我如何在抽屉堆栈屏幕中注销应用程序?我只是使用这个(props.navigation.navigate(“登录”))。移动到登录后,当用户再次按下后退按钮时,他将导航到上一个堆栈。我想清除所有堆栈并导航到登录。使用此选项,它将重置堆栈: 从“react navigation”导入{St

在我的应用程序中,我有一个主堆栈导航器(登录、抽屉)。我在react native中创建了一个抽屉导航器(“react navigation/drawer”:“^5.1.1”)。每个抽屉中都有一个堆栈导航器。那么,我如何在抽屉堆栈屏幕中注销应用程序?我只是使用这个(props.navigation.navigate(“登录”))。移动到登录后,当用户再次按下后退按钮时,他将导航到上一个堆栈。我想清除所有堆栈并导航到登录。

使用此选项,它将重置堆栈:

从“react navigation”导入{StackActions,NavigationActions}

const resetAction = StackActions.reset({
  index: 0,
  actions: [NavigationActions.navigate({ routeName: 'Login' })],
});
this.props.navigation.dispatch(resetAction);

我是如何通过创建两个堆栈并将其集成到主堆栈导航器中实现这一点的,我使用了底部选项卡,它与您的侧边抽屉非常相似

首先,我创建了一个不同的BottomTab堆栈:

const BottomTab = () => {
  return (
    <Tab.Navigator
      tabBarOptions={{
        activeTintColor: '#fff',
        activeBackgroundColor: '#c47808',
        inactiveBackgroundColor: '#ffbd5c',
        inactiveTintColor: '#c47808',
        style: {
          height: Platform.OS == 'ios' ? hp('10.35%') : hp('8.35%'),
        },
        labelStyle: {
          marginBottom: Platform.OS == 'ios' ? 8 : 2,
        },
      }}
      screenOptions={({route}) => ({
        tabBarIcon: ({focused, color, size}) => {
          return getTabBarIcon(route, focused);
        },
      })}>
      <Tab.Screen name="Home" component={Home} />
      <Tab.Screen name="Meetings" component={Meeting} />
      <Tab.Screen name="My Profile" component={Profile} />
      <Tab.Screen name="Settings" component={Settings} />
    </Tab.Navigator>
  );
};
您在..中为上述内容检查文档


希望能有帮助。不要怀疑

你发现了什么@高鵬翔 谢谢兄弟。“很好,很高兴它起了作用。如果你把答案也标记为已接受,这会很有帮助,如果它对你有帮助的话:D
 <NavigationContainer linking={deepLinking}>
        <Stack.Navigator
          initialRouteName="Login"
          screenOptions={{
            headerShown: false,
            gestureEnabled: false,
          }}>
          <Stack.Screen name="Login" component={LoginScreen} />
          <Stack.Screen name="SignupEmail" component={SignupEmail} />
          <Stack.Screen name="BottomTab" component={BottomTab} />   
        </Stack.Navigator>
      </NavigationContainer>
import { CommonActions } from '@react-navigation/native';

navigation.dispatch(
  CommonActions.reset({
    index: 1,
    routes: [
      { name: 'Home' },
      {
        name: 'Profile',
        params: { user: 'jane' },
      },
    ],
  })
);