React native push Notification ontap Navigation

Viewed 18

Hello i am Working Push Notification with the help of this https://github.com/zo0r/react-native-push-notification my notification is working fine but i want to navigate the the screen when i tap on notification ! my notifiaction working fine please help me out with any suggestion i used stack navigator in my routes

             onNotification: function (notification) {
              console.log("NOTIFICATIONss:", notification);
              if (notification.userInteraction) {
                console.log("Clicked on Notification"). // here i clicked on notification
                this.props.navigation.push("Home"). // here i want navigation
              }
             
              if (!notification.userInteraction) {
                PushNotification.localNotification({
                  foreground:false,
                  channelId: notification.channelId,
                  channelName: "xShare", // 
                  title: notification.title,
                  message: notification.message,
                  largeIconUrl: notification.smallIcon,
                  onOpen: () => { this.props.navigation.navigate("ActiveNeed") },//nothing working
                })
                notification.finish(PushNotificationIOS.FetchResult.NoData);
              }
            },`
1 Answers

If your app is opened through clicking on the notification bubble, the navigation props should be unavailable when the onNotification() function runs.

Therefore, please create a navigation reference for the app. You may follow the guidelines by React-Navigation for more details. https://reactnavigation.org/docs/navigating-without-navigation-prop

You can use the following code for navigation in onNotification() after you added the navigation-reference.

import * as RootNavigation from './path/to/RootNavigation.js';

RootNavigation.navigate('TargetPage', { someParams: 'someValue' });
Related