问题
I'm making app with using React Native with react-navigation.
[My App's hierarchy]
*Drawer(App)
ㄴ StackNavigator
ㄴ StackNavigator
What I want to is fire navigation.navigate('DrawerOpen');
I can show my Drawer by dragging from left edge but it's not triggered by pressing "Menu button" on the left of Navigation header. I've spent so many times to archive this. Please help me.
const Nav = StackNavigator({
mainnav_list:{
screen: (props) => <TodoList {...props} dbCollectionName={props.screenProps.dbCollectionName}/>,
navigationOptions:({navigation}) => ({
headerLeft:(
<TouchableOpacity onPress={() => {console.log(navigation); navigation.navigate('DrawerOpen');}}>
<Text style={{color:'white', marginLeft:15}}>Menu</Text>
</TouchableOpacity>
)
})
},
mainnav_detail:{screen: TodoDetail}
}
,
{
navigationOptions:(props) => ({
title:props.screenProps.dbCollectionName,
headerBackTitle:null,
headerStyle:{backgroundColor:'#000'},
headerTitleStyle:{color:'#fff'},
headerTintColor:'#fff',
})
})
const AppDrawer = DrawerNavigator(
{
drawer1:{screen:() => <Nav screenProps={{dbCollectionName:'todos'}}/> },
drawer2:{screen:() => <Nav screenProps={{dbCollectionName:'todos2'}}/> }
})
AppRegistry.registerComponent('TodosFS', () => AppDrawer);
回答1:
in new version of reactnavigation for open, close or toggle your DrawerNavigator
Just use the following
this.props.navigation.openDrawer();
this.props.navigation.closeDrawer();
this.props.navigation.toggleDrawer();
https://reactnavigation.org/docs/en/drawer-based-navigation.html
回答2:
I solved it!!
const Nav = StackNavigator({
mainnav_list:{
screen: (props) => <TodoList {...props} dbCollectionName={props.screenProps.dbCollectionName}/>,
navigationOptions:(props) => ({
headerLeft:(
<TouchableOpacity onPress={() => {props.screenProps.drawerNavigation.navigate('DrawerOpen');}}>
<Text style={{color:'white', marginLeft:15, fontWeight:'bold'}}>Menu</Text>
</TouchableOpacity>
)
})
},
mainnav_detail:{screen: TodoDetail}
}
,
{
navigationOptions:(props) => ({
title:props.screenProps.dbCollectionName,
headerBackTitle:null,
headerStyle:{backgroundColor:'#000'},
headerTitleStyle:{color:'#fff'},
headerTintColor:'#fff',
})
})
const AppDrawer = DrawerNavigator(
{
drawer1:{screen:({navigation}) => <Nav screenProps={{dbCollectionName:'todos', drawerNavigation:navigation}}/> },
drawer2:{screen:({navigation}) => <Nav screenProps={{dbCollectionName:'todos2', drawerNavigation:navigation}}/> }
})
AppRegistry.registerComponent('TodosFS', () => AppDrawer);
来源:https://stackoverflow.com/questions/47794833/nested-drawer-stacknavigator-firing-draweropen-is-not-working-on-react-native