The feature to disable open gesture hiding in Navigation Drawer on React Native seems to be malfunctioning

Our application utilizes a Navigation Drawer to display the side menu. However, there are certain screens where we do not want this navigation drawer to appear when the user performs left or right gestures.

We have attempted to hide these particular screens from the drawer interaction by utilizing code like drawerLockMode:"locked-closed" and disableOpenGesture: true, but unfortunately, they have not been successful in preventing the drawer from opening upon swipe gestures.


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

It should be noted that I am using version "react-navigation": "^3.0.9".

Do you have any suggestions on how to effectively disable the navigation drawer from being opened by gestures?

Answer №1

Could you please test out this code snippet?

const Navigator = 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
      }
    );
Navigator.navigationOptions = ({ navigation }) => {
  const options = {};
  if (getCurrentRoute(navigation.state) === 'Register') {
    options.drawerLockMode = 'locked-closed';
  }
  return options;
};

Alternatively, for react-navigation version V2,

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

The getCurrentRoute function

function getCurrentRoute(navState) {

    if (navState.hasOwnProperty('index')) {
        this.getCurrentRoute(navState.routes[navState.index])
    } else {
        console.log("Current Route:", navState.routeName)
        // can save this to the state (using redux)
        store.dispatch(setCurrentRoute(navState.routeName))
    }

}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What advantages do interfaces as data types offer in Angular compared to using classes?

After watching a tutorial from my teacher, he showed us this code snippet: https://i.sstatic.net/MA3Z9.png He mentioned that the products array, defined as type any [], is not taking advantage of TypeScript's strongly typing. He suggested using an I ...

Encountering a challenge with Nuxt where I am unable to navigate back when utilizing the require method

After successfully viewing the image, I encountered an error when trying to navigate back using <NuxtLink :to="{ path: 'About', hash: '#secondNav' }" class="close">, which resulted in a message stating Cannot f ...

Tips for retrieving specific database entries using a JavaScript function

I'm currently in the process of developing a web directory that showcases organizations based on the selected county by utilizing an XML database. During testing, I have configured it to only display organization names and counties for now. However, ...

Clicking on the ActionButton will trigger the sending of an HTTP Request in this Firefox

Seeking guidance: As I develop an addon, my objective is to initiate a HTTP request upon clicking the ActionButton. The data to be sent to the server includes the URL of the tab and the content of the page. Initially, I attempted to create a log message a ...

Elegant CSS background image fade effect

Having a small JS script that functions properly, but encountering an issue when quickly hovering over buttons causing the smooth transition effect to not work as desired. This abrupt change in image is quite unappealing. Any help would be greatly appreci ...

Using various hues for segmented lines on ChartJS

I am working with a time line chart type and I want to assign colors to each step between two dots based on the values in my dataset object. In my dataset data array, I have added a third item that will determine the color (if < 30 ==> green / >3 ...

Upgrade the arrow accordion in bootstrap by incorporating images instead

I have implemented a Bootstrap accordion with a toggle arrow. Here is an example: http://jsfiddle.net/zessx/r6eaw/12/ My question is, if I want to change the arrow with an image, what do I need to edit? Or how can I implement it? This is the image I want ...

"Dynamic Axis Scaling in Bokeh: A Versatile Feature

I have a situation similar to the one discussed in this question on Stack Overflow, but with additional code examples. In my Django app, I've built a Bokeh chart that visualizes the times swam in competitive swimming events over time. The chart utiliz ...

The for loop is not pausing to wait for the callback to complete within the loop

My objective is to display multiple .stl files in various divs on a webpage and retrieve model information for each model (such as volume, area, xyz coordinates, etc.). To accomplish this, I am utilizing , which is built on three.js The HTML code snippet: ...

"Learn the trick to concealing a modal and unveiling a different one with the power of jquery

Whenever I try to open a modal, then click on a div within the modal in order to close it and open another one, I encounter an issue. The problem is that upon closing the first modal and attempting to display the second one, only the background of the seco ...

Sending a parameter to the load method of the Selectize jQuery extension

I have a question about using the Selectize jQuery plugin for a dropdown box. I am not very familiar with jQuery, so please bear with me if this is a simple issue. I am making an ajax call to fetch data for the dropdown, but I need to pass a variable to th ...

What is the best way to showcase information from an external API in react js?

As I develop my new app, I am integrating API data from . This feature will enable users to search for their favorite cocktail drinks and display the drink name fetched from the API on the page. However, I am encountering an error that says "Uncaught TypeE ...

Securing access across multiple routes in a React application

I am facing a challenge in my React app where I need to verify the logged-in state before allowing access to multiple routes. Despite consulting various resources like Stack Overflow for solutions such as creating a Private Route, I have only found example ...

Fontawesome is unable to update the class due to the presence of invalid characters in the string

const toggleDarkOrLight = document.getElementsByTagName('i')[0]; var toggled = false; const toggleFunction = () => { if (toggled === false) { toggleDarkOrLight.classList.remove('fa fa-toggle-off'); toggleDarkOrLight.classLi ...

Dealing with HTML fields that share the same name in various positions can be tricky

Currently, I have developed a non-commercial web application using basic HTML, PHP, and Javascript along with Dynamic Drive's Tab Content code. This app serves as a tool for managing the books in my home library as well as on my ereader. My main goal ...

Wait for the completion of a Promise inside a for-loop in Javascript before returning the response

After completing a Promise within a for-loop, I am attempting to formulate a response. Although I have reviewed these questions, my scenario remains unaddressed. The methodGetOrders and methodGetLines are components of an external library that must be ut ...

Enclose each instance of "Rs." with <span class="someClass">

I'm facing an issue with the currency symbol "Rs." appearing in multiple places on my website. I want to enclose every instance of this text within <span class="WebRupee">. However, if it's already wrapped in <span class="WebRupee">, ...

Unable to establish connection between Router.post and AJAX

I am currently in the process of developing an application to convert temperatures. I have implemented a POST call in my temp.js class, which should trigger my ajax.js class to handle the data and perform calculations needed to generate the desired output. ...

How to incorporate a variable into an AngularJS expression?

As a newcomer to Angular, I have a question about using JS variables in an AngularJS expression. I am unsure if it is even called an expression, but the concept I am trying to convey can be illustrated as follows: <code> <script src= "http:// ...

Missing dots on owl carousel

Currently, I am working on a project that involves using the owlcarousel library in javascript. Everything was running smoothly until I encountered an issue. Although I have set the dots to true in the code, they are not appearing on the carousel. Below i ...