1

我必须在两侧做 2 个抽屉和一个底部标签导航器。我试图用 react-navigation 来做,但我做不到,因为 openDrawer 代码只打开了其中一个,所以我卡住了,请帮帮我。我怎样才能给抽屉 ID、钥匙或其他方法。

反应原生


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

我试过你的代码,但我得到了 TypeError: undefined is not an object (evalating '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>

4

1 回答 1

0

每个drawerNavigator都可以positioned和Route命名。Position可以设置为。然后通过命令打开drawer你想要的。

例子

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

用法

this.props.navigation.dispatch(DrawerActions.openDrawer('LeftSideMenu'));
于 2019-08-22T14:14:31.223 回答