stackNavigator里面的drawerNavigator的contentComponent

问题描述 投票:0回答:1

我正在用抽屉导航器构建一个应用程序。我应该有contentComponent制作的自定义侧面菜单屏幕,但问题是我需要在用户按下按钮时在抽屉内进行导航。我试图将stackNavigator传递给customComponent,这使我返回“没有为key定义路由......”。

拜托,你能帮助我,在抽屉里面导航而不关闭它。

const tempSN = createStackNavigator(
  {
    screen: DrawerScreen,
    screen2: ProfileSetupScreen
  },
  { initialRouteName: "screen" }
);

const DrawerStack = createDrawerNavigator(
  {
    MainStack: MainStack
  },
  {
    contentComponent: tempSN, // If I pass here DrawerScreen directly, it works
    navigationOptions: {
      header: null
    }
  }
);
react-native react-navigation
1个回答
1
投票

你可以尝试以下???

const DrawerStack = createDrawerNavigator(
  {
    MainStack: MainStack
  },
  {
    contentComponent: drawerComponent,//Your drawer component.Not stack navigator.
    navigationOptions: {
      header: null
    }
  }
);

const drawerStack = createStackNavigator(
  {
    drawerNav: DrawerStack,// Here is the drawer included.
    screen: DrawerScreen,
    screen2: ProfileSetupScreen
  },
);

在堆栈导航中添加抽屉导航。当你想导航到屏幕'screen2'时,使用像this.props.navigation.navigate("screen2")

© www.soinside.com 2019 - 2024. All rights reserved.