简体   繁体   中英

disableOpenGesture hiding is not working Navigation Drawer react native

We are using Navigation Drawer in our application to show side menu. In a few of the screens we don't want to show this navigation drawer once user tried to do left/right gestures.

So, for that, we are trying to hide a particular screen - gestures/navigationdrawer - but it's not working. When the user swipes (left/right) the drawer still opens.


    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
      }
    );

We have tried both drawerLockMode:"locked-closed" and disableOpenGesture: true but nothing is working.

Note: I am using "react-navigation": "^3.0.9" version

Any suggestions to disable navigation drawer being opened by gestures?

can you try this code?

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;
};

OR If your react-navigation version is V2,

const Stack = createStackNavigator({
    Register: Register,
},
    {
        drawerLockMode: 'locked-closed'
    }
);

getCurrentRouteName function

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))
    }

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM