Notification custom action on "click" the notification

Hi, I’d like to open specific screen when the user click on the notification(like whatsapp) but I don’t know how to do it, I try to add a listener to the notification:

 Notifications.addListener(notification => {
         var user= AsyncStorage.getItem('user').then(function(userStr){
             if (userStr !== null) {
                 var user = JSON.parse(userStr);
                 this.props.navigation.navigate('Chat', {conversationId: -1,user: user});

But every time I’m in the main screen for example and send a push notification this Listener is triggered without the push notification, how can I do it? I don’t know how to trigger a custom action when the notification is “click” and not when is received

Hey @patofet,

You’ll want to read the notification payload and check the origin value like so:

_handleNotification = notification => {
    let { origin, data } = notification;
    if (origin === "selected") {

Selected means the notification was tapped by the user.


1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.