Nesting multiple navigators

拟墨画扇 提交于 2019-12-24 18:41:08

问题


I'm trying to integrate StackNavigator, TabNavigator and DrawerNavigator like this:

class TestApp extends Component {
  render() {
    return (    
        <MyApp />
    );
  }
}

const Tabs = TabNavigator({
  Home1: { screen:Home1 },
  Home2: { screen:Home2 },
  },
  { 
  tabBarPosition: 'bottom',
}); 

const Drawer = DrawerNavigator({
  First:{
    screen: DrawerScreen1
  },
  Second:{
    screen: DrawerScreen2
  }
},{
  initialRouteName:'First',
  drawerPosition: 'left'
});

const MyApp = StackNavigator({
  Screen1: {screen:Screen1},
  Screen2: {screen:Screen2},
  Tabs: {
     screen: Tabs
  },
  Drawer:{
    screen: Drawer
  }
}, {
   initialRouteName: "Tabs"
});


AppRegistry.registerComponent('TestApp', () => TestApp);

Calling the drawer:

<Button
  onPress={() => this.props.navigation.navigate('DrawerOpen')}
  title="Show Drawer"
/>

It does not open the drawer. It opens the DrawerScreen1 as if I'm calling it from StackNavigator. It opens the component with a back button. I want to open the drawer.

DrawerScreen1:

export default class DrawerScreen1 extends Component{
  static navigationOptions = {
    drawerLabel: 'Home',
    drawerIcon: ({ tintColor }) => (
       <Image
        source={require('./myImage.png')}
        style={height:100, width: 100}
       /> 
    ),
  };
render() {
    return (
      <Button
        onPress={() => this.props.navigation.navigate('DrawerOpen')}
        title="DrawerOpen"
      />
    );
  }
}

DrawerScreen2 is similar. What am I missing? Please help.

来源:https://stackoverflow.com/questions/46775295/nesting-multiple-navigators

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!