我的react navigation
设置如下。当在抽屉组件外面按一下时,可以关闭抽屉。 (但是当我单击bottom navigator tabs part
时不可以)。
单击底部导航时如何关闭抽屉?
const HomeFilterDrawer = createDrawerNavigator(
{
Home: {
screen: HomeScreen,
navigationOptions: ({navigation}) => ({
header: null,
}),
},
},
{
initialRouteName: 'Home',
contentComponent: DrawerComponent,
drawerPosition: 'right',
},
);
const HomeScreenStack = createStackNavigator(
{
Home: {
screen: HomeFilterDrawer,
navigationOptions: ({navigation}) => ({
header: null,
}),
},
Search: {
...
},
}
);
const AppNavigator = createBottomTabNavigator(
Home: {
screen: HomeScreenStack,
navigationOptions: {
tabBarLabel: 'Home,
tabBarIcon: tabInfo => {
return (
<Ionicons name="ios-home" size={25} />
);
},
tabBarOnPress: ({navigation}) => {
navigation.popToTop();
navigation.navigate(navigation.state.routeName);
},
},
},
);
答案 0 :(得分:0)
您尝试使用DrawerActions
关闭抽屉吗?
import { DrawerActions } from '@react-navigation/routers';
// ...
// in tabbaronPress call the following
navigation.dispatch(DrawerActions.closeDrawer());