我使用react-navigation并尝试在TabNavigator中点击标签项时打开抽屉(使用DrawerNavigator)。我目前的代码如下:
class OpenDrawerScreen extends Component {
componentWillMount() {
this.props.navigation.navigate("DrawerOpen"); // Opening Drawer
}
render() {
return (
<View style={styles.container}>
<Text>Dummy view - Nothing to see here.</Text>
</View>
)
}
}
const TabNav = TabNavigator({
TabItem1: {
screen: TabOneScreen,
navigationOptions: {
tabBarLabel:"Tab 1"
}
},
TabItem2: {
screen: OpenDrawerScreen,
navigationOptions: {
tabBarLabel:"Open Drawer"
}
}
}, {
tabBarPosition: 'bottom'
});
const DrawerNav = DrawerNavigator({
DrawerItem1: {
screen: TabNav,
navigationOptions: {
drawer: {
label: 'Drawer 1'
},
},
},
});
export default class App extends Component {
render() {
return (
<DrawerNav />
);
}
}
但是这不起作用,结果是,每次应用程序启动时抽屉都会打开,而不是仅在点击“打开抽屉”时才打开抽屉。标签项。是否有其他生命周期方法我应该打开抽屉而不是从componentWillMount()方法打开,还是有另一种方法呢?
感谢。