静态navigationOptions =({navigation})=> { 返回{ headerLeft :( {navigation.navigate('DrawerOpen')}} /> ) } }
答案 0 :(得分:2)
由React Navigation(v2)提供。您可以在https://reactnavigation.org/docs/en/drawer-based-navigation.html
中找到文档您需要在下面这样使用
static navigationOptions = ({ navigation }) => ({
headerLeft: <Button onPress={() => navigation.toggleDrawer()} />
})
要打开和关闭抽屉,请使用以下助手来打开和关闭抽屉:
this.props.navigation.openDrawer();
this.props.navigation.closeDrawer();
如果要切换抽屉,请调用以下命令:
this.props.navigation.toggleDrawer();
这些功能中的每一个都只是在幕后调度动作:
this.props.navigation.dispatch(DrawerActions.openDrawer());
this.props.navigation.dispatch(DrawerActions.closeDrawer());
this.props.navigation.dispatch(DrawerActions.toggleDrawer());
答案 1 :(得分:0)
这为我解决了导航问题。
通过运行npm install --save native-base
运行react-native link
链接字体
导入此import {Header, Left, Icon} from 'native-base'
将此代码添加到render(){}
render() {
return (
<View>
<Header>
<Left>
<Icon name="menu" style={{ color: 'white'}}
onPress={() => this.props.navigation.toggleDrawer()} />
</Left>
</Header>
<View>
<Text>Home Contents</Text>
</View>
</View>
);
}