Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to conditionally disable the swipe to go back gesture in react native iOS?

I'm looking for a way to conditionally disable the swipe to go back gesture in react native iOS. I'm using the react-navigation library to control navigation. For Android, I am able to do it using BackHandler. Is it possible to do something similar in iOS?

  componentDidMount() {
      BackHandler.addEventListener("hardwareBackPress", this.handleBackButton);
  }

  handleBackButton = () => {
    if (this.props.creating) {
      return true; // Disables the back button in Android
    }
  };

  componentWillUnmount() {
      BackHandler.removeEventListener(
        "hardwareBackPress",
        this.handleBackButton
      );
  }
like image 551
Arun Kumar Avatar asked Sep 18 '25 13:09

Arun Kumar


1 Answers

Yes, there is an option to disable gestures:

screen: ExampleView
    navigationOptions: {
        gesturesEnabled: false,
    },

Check for more details here: https://github.com/react-navigation/react-navigation/issues/1063

like image 133
mmmatey Avatar answered Sep 20 '25 03:09

mmmatey