title: React Navigation without navigation prop does not work in release mode (Android signed app)
body: <p>I am implementing a react-native app that receives firebase push notification. When a notification arrives the app navigate to a screen to show the notification.
  I followed this approach using reference:
  "Navigating without the navigation prop"
  <a href="https://reactnavigation.org/docs/en/navigating-without-navigation-prop.html" rel="nofollow noreferrer">https://reactnavigation.org/docs/en/navigating-without-navigation-prop.html</a></p>
  
  <p>When I tested this with debug mode, it works perfectly. But when I tested in release mode (android signed app) it does not work.</p>
  
  <p>Especially, when the notification arrives when the app is open, it does not work. There is no error message and the app become freezing and in a 30 seconds or so, the app crashes.</p>
  
  <p>Here are package info:</p>
  
  <pre><code>    "react": "16.8.3",
      "react-i18next": "10.12.2",
      "react-native": "0.59.10",
      "react-native-firebase": "5.5.6",
      "react-native-gesture-handler": "1.3.0",
      "react-navigation": "3.11.1",
  </code></pre>
  
  <p>Basically, I tried this
  "Navigating without the navigation prop"
  <a href="https://reactnavigation.org/docs/en/navigating-without-navigation-prop.html" rel="nofollow noreferrer">https://reactnavigation.org/docs/en/navigating-without-navigation-prop.html</a></p>
  
  <p>Similarly, this one too:
  <a href="https://github.com/react-navigation/react-navigation/issues/742" rel="nofollow noreferrer">https://github.com/react-navigation/react-navigation/issues/742</a></p>
  
  <p>I am using not class component but functional component.</p>
  
  <p>// Navigator.js</p>
  
  <pre><code>const switchNavigator = createSwitchNavigator({
    ResolveAuth: ResolveAuthScreen,
    loginFlow: createStackNavigator({
      Signin: SigninScreen,
      Signup: SignupScreen
    }),
    helpFlow: createStackNavigator({
      Help: HelpScreen,
    }, {headerLayoutPreset: 'center'}),
    mainFlow: createBottomTabNavigator({
      Ask: createStackNavigator({
        AskMain: AskScreen,
        AskWait: AskWaitScreen,
      }, {headerLayoutPreset: 'center'}),
      Chat: createStackNavigator({
        ChatList: ChatListScreen,
        Chatting: ChatScreen,
      }, {headerLayoutPreset: 'center'}),
      Profile: createStackNavigator({
        Account: AccountScreen,
        AccountEdit: AccountEditScreen,
        ProfileContract: ProfileScreen
      }
      , {headerLayoutPreset: 'center'})
    },
  ...
  export default createAppContainer(switchNavigator);
  </code></pre>
  
  <p>// App.js</p>
  
  <pre><code>import Navigator from './Navigator';
  import { useTranslation } from 'react-i18next';
  import { navigate, setNavigator } from './src/navigationRef';
  
  const App = Navigator;
  
  export default () =&gt; {
  
    // setup language
    const { t } = useTranslation();
  
    // use effect
    useEffect(() =&gt; {
  
      // notification listener (triggered when a particular notification has been received)
      // if the app is foreground, we need to navigate the screen
      const listenerFG = firebase.notifications().onNotification((notification: Notification) =&gt; {
        console.log('onNotification', notification);
        Alert.alert(
          t('AppScreen.title'),
          t('AppScreen.message'),
          [
            {text: t('yes'), onPress: () =&gt; navigate('Help', { notificationBody: notification })},
          ],
          {cancelable: true},
        );
      });
  
     listenerForAppClosed();
  
     return () =&gt; {
        listenerFG();
      }
    }, []);
  
    return (
      &lt;App ref={(navigator) =&gt; { setNavigator(navigator) }} /&gt; 
    );
  </code></pre>
  
  <p>// navigationRef.js</p>
  
  <pre><code>import { NavigationActions } from 'react-navigation';
  
  let navigator;
  
  // nav is coming from react navigation
  export const setNavigator = navRef =&gt; {
    console.log('navigation ref', navRef);
    // set navigator
    navigator = navRef;
  };
  
  export const navigate = (routeName, params) =&gt; {
    console.log('[navigate dispatch] navigator', navigator);
    navigator.dispatch(
      NavigationActions.navigate({
        routeName,
        params
      })
    );
  };
  </code></pre>
  
  <p>In debug mode, using `navigate('any screen') works like a charm, but in release mode, it does not work.</p>
  
  <p>But one strange thing is that the following navigation works. A user opens a push notification when the app is not foreground state. </p>
  
  <p>// part of App.js</p>
  
  <pre><code>// listen the notification being opened or clicked when the app is closed
    const listenerForAppClosed = async() =&gt; {
      // app closed
      const notificationOpen: NotificationOpen = await firebase.notifications().getInitialNotification();
      if (notificationOpen) {
        // app was opened by a notification
        console.log('getInitialNotification', notificationOpen);
        // get information about the notification that was opened
        const notification: Notification = notificationOpen.notification;
        //// ignore the same notification id since the same notification is received again, don't know why.
        // get noti id from storage
        const notiId = await AsyncStorage.getItem('notiId');
        // set noti id to storage
        await AsyncStorage.setItem('notiId', notification.notificationId);     
        if (notification.notificationId === notiId) {
          console.log('notification id is the same');       
        } else { 
          console.log('navigating to helpscreen...');   
          // navigate to Help screen
          navigate('Help', { notificationBody: notification });
        }
      }
    }
  </code></pre>
  
  <p>The problem happens both on Android emulator and a device (Android9).</p>
  
  <p>Why the navigate('Help') does not work in release mode? I searched many documents and I feel that it should work in release mode too.</p>
  
  <p>Is there any other way to navigate to a screen from top-level (like App.js)?</p>