如何在REACT NATIVE中打开第二个抽屉

时间:2019-08-22 13:50:10

标签: react-native react-native-drawer

我必须在两侧都做两个抽屉,并在底部有一个标签导航器。我试图用react-navigation来做到这一点,但是我不能,因为openDrawer代码只是打开其中一个,所以我坚持了,请帮助我。如何提供抽屉ID,密钥或其他方法。

反应原生


<Button onPress={this.props.navigation.openDrawer}>
<Button/>  //left drawer opens 
<Button onPress={this.props.navigation.openDrawer}>
<Button/>

我尝试了您的代码,但出现TypeError:undefined不是对象 (评估“ this.props.navigation.dispatch”)

<Button title='open the drawer' onPress={this.props.navigation.dispatch(DrawerActions.openDrawer('drawerOpenLeft'))}></Button>
        <Button title='open the drawer right' onPress={this.props.navigation.dispatch(DrawerActions.openDrawer('drawerOpenRight'))}></Button>

1 个答案:

答案 0 :(得分:0)

每个drawerNavigator可以是positioned并命名为Route。 Position可以设置为。然后通过命令打开所需的drawer

示例

let LeftSideMenuDrawer = createDrawerNavigator({
...
    drawerOpenRoute: 'LeftSideMenu',
    drawerCloseRoute: 'LeftSideMenuClose',
    drawerToggleRoute: 'LeftSideMenuToggle',
....

用法

this.props.navigation.dispatch(DrawerActions.openDrawer('LeftSideMenu'));