简体   繁体   English

如何在反应导航中从抽屉堆栈导航到开关堆栈?

[英]How can i navigate from a Drawer Stack to a Switch Stack in react navigation?

I'm using React-navigation V3. 我正在使用React-navigation V3。 How can I navigate from MenuDrawer in contentComponent to a Login screen in the Swith Navigator?? 如何从contentComponent中的MenuDrawer导航到Swith导航器中的登录屏幕?

This is my switch Navigator (my login). 这是我的开关导航器(我的登录名)。

const AppContainer = createAppContainer(createSwitchNavigator(
  {
    VerifyActiveUser,
    ActProgramadas: MainDrawer,
    Login,
    SyncData
  },
  {
    initialRouteName: 'VerifyActiveUser',
  }
));

export default class StackNavigator extends Component{
  render(){
      return <AppContainer 
      />;
  }
}

This is my Drawer Stack (MainDrawer). 这是我的抽屉堆栈(MainDrawer)。 MenuDrawer is my custom drawer, from there i want to go to Login Screen (From Switch Navigator) with a "go out" Button to end my user session but i don't know how to send navigations props to contentComponent of my drawer: MenuDrawer是我的自定义抽屉,从那里我想用一个“出门”按钮转到登录屏幕(从Switch Navigator)来结束我的用户会话,但是我不知道如何将导航道具发送到抽屉的contentComponent:

const DrawerConfig ={
    drawerWidth: WIDTH * 0.86,
    contentComponent: ({navigation}) => {
        return (<MenuDrawer navigation = { navigation } />);
    },
    contentOptions: {
        activeTintColor: 'blue',
        activeBackgroundColor: 'green'
    },
    initialRouteName: 'ActProgramadas',
    unmountInactiveRoutes: true,
    edgeWidth: WIDTH * 0.80,
    backBehavior: false
}

const MyDrawerNavigator = createDrawerNavigator({
    ActProgramadas: { screen: StackNavigator },
    ActRealizadas: { screen: StackActReal },
    ObsTecnicas: { screen: StackObs },
    ObsPendientes: { screen: StackObsPend },
    ObsRealizadas: { screen: StackObsReal },
    SyncData
}, DrawerConfig);

const AppContainer = createAppContainer(MyDrawerNavigator)

export default class DrawerNavigator extends Component{
    render(){
        return <AppContainer />;
    }
}

Can I use redux to send the navigation.navigate('Login') prop from the swith to my custom drawer?? 我可以使用redux将swith的navigation.navigate('Login')道具发送到我的自定义抽屉吗?

You can add a logout screen in your drawer. 您可以在抽屉中添加注销屏幕。 The screen is a React component which defines the logout behavior on mounting: 该屏幕是一个React组件,它定义了安装时的注销行为:

import React from 'react';
import { View, AsyncStorage, ActivityIndicator, StatusBar } from 'react-native';


export default class LogoutScreen extends React.Component {
  async componentDidMount() {
      await AsyncStorage.clear();
      this.props.navigation.navigate('Login');
  }

  render() {
    return (
      <View>
        <ActivityIndicator />
        <StatusBar barStyle='default' />
      </View>
    );
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 React Navigation,如何强制抽屉导航器弹出到堆栈顶部? - Using React Navigation, how can I force the drawer navigator to pop to the top of the stack? 在React Native中如何在重置导航堆栈的同时从子Stack Navigator导航回父项 - How to navigate from a child Stack Navigator back to parent while resetting navigation stack at the same time, in React Native React Native 中的堆栈导航和抽屉导航 - Stack navigation and Drawer navigation in React Native 如何在 React Navigation 中返回堆栈导航? - How can I go back on Stack Navigation in React Navigation? React Native Navigation:在另一个文件的函数内部时无法在堆栈之间导航 - React Native Navigation : can't navigate between stack when inside a function from another file 使用 React Navigation 5,如何使导航到抽屉项目重置该堆栈的 state? - With React Navigation 5, how do I make navigating to a drawer item reset the state of that stack? React Native中带抽屉和堆栈导航器的嵌套导航 - Nested Navigation with drawer and stack navigator in React Native 如何使用Stack Actions在反应导航中重置路线? - How I can reset route in react-navigation with Stack Actions? 无法使用 React Native 从 Navigation 5 中的抽屉内部导航 - Can't navigate from inside drawer in Navigation 5 using React Native 如何在现有项目的堆栈导航器中添加导航抽屉 - How can i add a navigation drawer inside a stack navigator in an already existing project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM