在我的应用程序中,我有3个堆栈 StackOne
export const StackOne = createStackNavigator({
OneScreen: { screen:one },
TwoScreen: { screen:two },
ThreeScreen: { screen:three },
}, { initialRouteName: 'OneScreen', }
);
StackTwo
export const StackTwo = createStackNavigator({
OneScreenTwo: { screen:oneTwo },
TwoScreenTwo: { screen:twoTwo },
ThreeScreenTwo: { screen:threeTwo },
}, { initialRouteName: 'OneScreenTwo', }
);
我这样使用抽屉式导航。 MainDrawer
const MainDrawer = createDrawerNavigator(
{
One: { screen: StackOne },
Two: { screen: StackTwo },
Other: { screen: OtherScreen},
},
{}
);
一切正常。管理抽屉-堆叠得很好
唯一的问题是当我在StackOne's ScreenTwo
左右滑动时仍打开抽屉菜单。
不仅每个屏幕上的该屏幕都打开抽屉菜单。
我尝试了几个链接,但找不到成功。 希望有人帮忙。 我点击此链接Navigation
谢谢
答案 0 :(得分:4)
您需要在StackNavigator上指定navigationOptions
而不是TwoScreen
等,否则将配置StackNavigator而不是DrawerNavigator:
StackOne.navigationOptions = ({ navigation }) => ({
drawerLockMode: navigation.state.index === 0 ? 'unlocked' : 'locked-closed',
});
答案 1 :(得分:0)
export const StackOne = createStackNavigator({
OneScreen: { screen:one },
TwoScreen: { screen:two },
ThreeScreen: { screen:three },
}, { initialRouteName: 'OneScreen', }
);
StackOne.navigationOptions = ({ navigation }) => {
let drawerLockMode = 'unlocked';
if (navigation.state.routes[navigation.state.index] != 'OneScreen') {
drawerLockMode = 'locked-closed';
}
return {
drawerLockMode,
};
};
export const StackTwo = createStackNavigator({
OneScreenTwo: { screen:oneTwo },
TwoScreenTwo: { screen:twoTwo },
ThreeScreenTwo: { screen:threeTwo },
}, { initialRouteName: 'OneScreenTwo', }
);
StackTwo .navigationOptions = ({ navigation }) => {
let drawerLockMode = 'unlocked';
if (navigation.state.routes[navigation.state.index] != 'OneScreenTwo') {
drawerLockMode = 'locked-closed';
}
return {
drawerLockMode,
};
};
创建导航选项并解决问题。