我们在应用程序中使用导航抽屉显示侧边菜单。 在某些屏幕中,我们不想在用户尝试左右手势时显示此导航抽屉。
因此,为此,我们正在尝试隐藏特定的屏幕-手势/导航抽屉-但不起作用。 当用户向左/向右滑动时,抽屉仍会打开。
const AppNavigator = StackNavigator(
{
// Drawer: { screen: Drawer },
Register: {
screen: Register,
navigationOptions: ({ navigation }) => ({
drawerLockMode: "locked-closed",
})
},
TabHome: { screen: TabHome },
Album: { screen: Album },
offlineContent: { screen: offlineContent },
changePassword: { screen: changePassword },
Player: {screen: Player},
},
{
initialRouteName: "TabHome",
// header: null
}
);
我们已经尝试了drawerLockMode:"locked-closed"
和disableOpenGesture: true
但什么都没用。
注意:我正在使用"react-navigation": "^3.0.9"
版本
是否有任何建议禁止手势打开导航抽屉?
答案 0 :(得分:0)
您可以尝试使用此代码吗?
const AppNavigator = StackNavigator(
{
// Drawer: { screen: Drawer },
Register: {
screen: Register
},
TabHome: { screen: TabHome },
Album: { screen: Album },
offlineContent: { screen: offlineContent },
changePassword: { screen: changePassword },
Player: {screen: Player},
},
{
initialRouteName: "TabHome",
// header: null
}
);
AppNavigator.navigationOptions = ({ navigation }) => {
const navigationOptions = {};
if (getCurrentRouteName(navigation.state) === 'Register') {
navigationOptions.drawerLockMode = 'locked-closed';
}
return navigationOptions;
};
或者如果您的反应导航版本是V2,则
const Stack = createStackNavigator({
Register: Register,
},
{
drawerLockMode: 'locked-closed'
}
);
getCurrentRouteName函数
getCurrentRouteName(navState) {
if (navState.hasOwnProperty('index')) {
this.getCurrentRouteName(navState.routes[navState.index])
} else {
console.log("Current Route Name:", navState.routeName)
// can then save this to the state (I used redux)
store.dispatch(setCurrentRouteName(navState.routeName))
}
}