title: React Navigation (V2): How to prevent (lock) the drawer from opening within a nested stack?
body: <p>I'm building an app using React Native and I use React Navigation for my navigation.</p>
  
  <p>In order to be able to have modals and regular card transitions for a stack as well have a burger menu, I have my <code>HomeStack</code> nested inside my <code>MainStack</code> which is inside my <code>MainDrawer</code>.</p>
  
  <p>The code looks like this:</p>
  
  <pre><code>const HomeStack = createStackNavigator({...});
  const MainStack = createStackNavigator({ HomeStack, ... }, { mode: "modal" });
  const MainDrawer = createDrawerNavigator({ MainStack, ... });
  </code></pre>
  
  <p>The problem is that inside the pages of my <code>HomeStack</code> the user is expected to do swipe motions which often lead to accidentally opening the drawer. Therefore I want to lock the drawer for the <code>HomeStack</code>, when screens have been pushed onto it.</p>
  
  <p>Here comes the problem: <a href="https://reactnavigation.org/docs/en/navigation-options-resolution.html#a-drawer-has-a-stack-inside-of-it-and-you-want-to-lock-the-drawer-on-certain-screens" rel="nofollow noreferrer">The docs give this solution</a>, but this does not work in my case, since the stack is nested inside another stack.</p>
  
  <pre><code>// What I tried and what (obviously?) won't work
  HomeStack.navigationOptions = ({ navigation }) =&gt; {
    let drawerLockMode = "unlocked";
    if (navigation.state.index &gt; 0) {
      drawerLockMode = "locked-closed";
    }
    return {
      drawerLockMode
    };
  };
  
  MainStack.navigationOptions = ({ navigation }) =&gt; {
    let drawerLockMode = "unlocked";
    if (navigation.state.index &gt; 0) {
      drawerLockMode = "locked-closed";
    }
    return {
      drawerLockMode
    };
  };
  </code></pre>
  
  <p>Is there any way to for example know about the child stack's state, so that I could use a similar technique to lock the drawer?</p>
  
  <pre><code>// Example pseudo code:
  MainStack.navigationOptions = ({ navigation }) =&gt; {
    let drawerLockMode = "unlocked";
    if (navigation.state.HomeStack.state.index &gt; 0) { // here!
      drawerLockMode = "locked-closed";
    }
    return {
      drawerLockMode
    };
  };
  </code></pre>
  
  <p>How can I solve this problem?</p>