0

My question is simple but I'm not being able to find any documentation about this.

I have a notification that the app sends to the user periodically if the user is not loggeIn, when the user taps on the notification it opens the app and opens the "Login" screen, the problem is that if the app is killed the app opens but it doesn't navigate to the "Login" screen, it stays at the home screen.

Any ideas how to do this?

Thank you very much in advance

Right now I'm using RootNavigation.navigate('Login') when the user taps on the notification.

dosorio
  • 23
  • 5

1 Answers1

1

Your problem is that navigation not loaded yet in moment you use Root Navigation.navigate(). You can make it like this

    const Deferred = () => {
    let d = {};
    d.promise = new Promise(function(resolve, reject) {
        d.resolve = resolve;
        d.reject = reject;
    });
    return d;
};
const navigationDeferred = new Deferred()

<NavigationContainer ref={navigationRef} onReady={()=>{navigationDeferred.resolve()}} >

 messaging()
    .getInitialNotification()
    .then(remoteMessage => {
        if (remoteMessage) {
            console.log(
                'Notification caused app to open from quit state:',
                remoteMessage.notification,
            );
            navigationDeferred.promise.then(()=>{
               NavHelper.navigate("YourScreen");;
            })
        }
    });
   

NavHelper it helper from documentation https://reactnavigation.org/docs/navigating-without-navigation-prop/

KetchUp
  • 11
  • 1
  • Thanks for your fast reply @KetchUp, but investigating a lot about the problem and find out that the Notifications.addNotificationResponseReceivedListener is not reading the interaction with the notification. So it's basically just opening the app and that's it. Any Idea what is causing this behaviour? then the app is in foreground or background it works – dosorio Nov 04 '22 at 10:21