0

I am using react-native-firebase on a project to implement push notifications. One request came in to make the user navigate to a specific screen whenever one taps on the push notif alert.

react-navigation is being used for the screen navigation. I use push to mimic an inbox feature in my app.

Can you please suggest the ways this can be implemented?

One solution would be to add the listener on a screen and the perform the navigation since in it will already have the navigation props. But I have too many screens. Another solution would be to have a reference to the root navigator and pass it to the pushnotification controller. But this fails as I use redux and if if I add the config option { withRef: true } , It complains saying that the ref passed is not a function.

Do you have a better way of doing it or indicate to me what am I doing wrong please?

Thanks and Kind Regards, Avinash

Avinash Lingaloo
  • 181
  • 3
  • 16
  • In android we have [Pending Intent](https://developer.android.com/reference/android/app/PendingIntent) you can look for similar to that. Example is here https://www.journaldev.com/10463/android-notification-pendingintent – nimi0112 Jul 28 '18 at 06:36

2 Answers2

0

I have a solution for you , you can add a listen in you App.js , save that notification in async storage and then Access that notification object on the same page where you handle the logic of login user if token is present (Checking if user is login you can navigate him to desired page ), there you can navigate user to desired screen , Here you can check two things ,

  • easily access to notification object , detect whether is clicked or received.
  • easy to user auth , which is must to check on push notification

Hope my answer make sense to you

HpDev
  • 2,789
  • 1
  • 15
  • 20
0

I'm using a tabNavigator. In the first screen, I simply call the firebase listeners for push notifications and then I do the navigation.

Avinash Lingaloo
  • 181
  • 3
  • 16
  • can you check this Q please, @AvinashLingaloo https://stackoverflow.com/questions/57171787/navigate-to-screen-after-opening-a-notification – DevAS Jul 23 '19 at 22:22