如何切换反应导航抽屉

use*_*437 3 react-native react-navigation

我在第一个react-native项目中使用react-navigation https://reactnavigation.org/。我想切换我的抽屉(打开和关闭),但是我不知道该如何实现。我一直在看reactnavigation.org上的文档,但实际上找不到任何提示。

vig*_*esh 5

如果您想切换抽屉,您可以导航到“DrawerToggle”,这将根据抽屉的当前状态选择适合您的导航。

相应地触发 'DrawerOpen&DrawerClose'

this.props.navigation.navigate('DrawerToggle');


小智 5

如React Navigation(v2)

要打开和关闭抽屉,请使用以下助手来打开和关闭抽屉:

this.props.navigation.openDrawer();
this.props.navigation.closeDrawer();
Run Code Online (Sandbox Code Playgroud)

如果要切换抽屉,请调用以下命令:

this.props.navigation.toggleDrawer();
Run Code Online (Sandbox Code Playgroud)

这些功能中的每一个在后台都只是在调度动作:

this.props.navigation.dispatch(DrawerActions.openDrawer());
this.props.navigation.dispatch(DrawerActions.closeDrawer());
this.props.navigation.dispatch(DrawerActions.toggleDrawer());
Run Code Online (Sandbox Code Playgroud)