question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Redirect to another screen

See original GitHub issue

I want to push another page when the user touch notification in another problem if i push an notification with actions like: actions: '["Accept", "Reject"]' it doesnt show the action selected if app is foreground.

please, help me i try this so hard without results

import React from 'react';
import AppNavigator from './AppNavigator';

//PUSH NOTIFICATION
var PushNotification = require('react-native-push-notification');

PushNotification.configure({

    // (optional) Called when Token is generated (iOS and Android)
    onRegister: function(token) {
        console.log( 'TOKEN:', token );
        //console.warn('TOKEN:', token.token);
    },

    // (required) Called when a remote or local notification is opened or received
    onNotification: function(notification) {
        console.log( 'NOTIFICATION:', notification );
        this.props.navigation.navigate('Details');
        // process the notification

        // required on iOS only (see fetchCompletionHandler docs: https://facebook.github.io/react-native/docs/pushnotificationios.html)
        //notification.finish(PushNotificationIOS.FetchResult.NoData);
    },

    // ANDROID ONLY: GCM or FCM Sender ID (product_number) (optional - not required for local notifications, but is need to receive remote push notifications)
    senderID: "MYSENDERID",

    // IOS ONLY (optional): default: all - Permissions to register.
    permissions: {
        alert: true,
        badge: true,
        sound: true
    },

    // Should the initial notification be popped automatically
    // default: true
    popInitialNotification: true,

    /**
      * (optional) default: true
      * - Specified if permissions (ios) and token (android and ios) will requested or not,
      * - if not, you must call PushNotificationsHandler.requestPermissions() later
      */
    requestPermissions: true,
});
//END

export default class App extends React.Component {
  render() {
    return (
      <AppNavigator/>
    );
  }
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12

github_iconTop GitHub Comments

3reactions
JoaquinDelPradocommented, Feb 21, 2019

@saadmutahar take this as an example:

`export default class Login extends React.Component {
  constructor(props){
    super(props);
    this.setToken = this.setToken.bind(this);
    this.handleNotification = this.handleNotification.bind(this);
  } 

  setToken(token){
   //your logic here, save the token
  };

  handleNotification(notification){
    //your logic here,
    console.warn(notification);

    let isBackground = notification.foreground;
    if(isBackground == true){
      this.props.navigation.navigate('Home');
    }
  };
async componentDidMount(){     
    //PUSH NOTIFICATION
    var that = this;
    PushNotification.configure({

      onRegister: function(token) {
        //Función para guardar token
        that.setToken(token);
      },

      onNotification: function(notification) {
        //Función para manejar notificaciones  
        that.handleNotification(notification);  
        //notification.finish(PushNotificationIOS.FetchResult.NoData); //Solo para IOS
      },

      senderID: "30438xxxxxxx",
      permissions: {
          alert: true,
          badge: true,
          sound: true
      },
      popInitialNotification: true,
      requestPermissions: true,
    });

}
0reactions
JoaquinDelPradocommented, Dec 26, 2019

Was there a solution for this?

Sure, take this example

async componentDidMount(){     
    //PUSH NOTIFICATION
    var that = this;
    PushNotification.configure({

      onRegister: function(token) {
        //Función para guardar token
        that.setToken(token);
      },

      onNotification: function(notification) {
        //Función para manejar notificaciones  
        that.handleNotification(notification);  
        //notification.finish(PushNotificationIOS.FetchResult.NoData); //Solo para IOS
      },

      senderID: "30438xxxxxxx",
      permissions: {
          alert: true,
          badge: true,
          sound: true
      },
      popInitialNotification: true,
      requestPermissions: true,
    });

}
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to redirect from Screen 1 to another Screen 2...
Hello, On the first screen i have a button with OnSelecte (Navigate(Screen2,ScreenTransition.
Read more >
How to redirect to other Screen without pressing button/link in ...
1 Answer 1 ... You have to use a state to know what screen to render, when that state change you must change...
Read more >
Redirect to different screen in other module - OutSystems
Hi All,. I want to redirect to a screen in different module moduleBa from module Ain reactive web,I have linked to redirect url ......
Read more >
Moving between screens - React Navigation
In this case, we know that we want to go back to Home so we can use navigate('Home') (not push ! try that...
Read more >
Navigate to a new screen and back - Flutter documentation
Navigate to a new screen and back · 1. Create two routes · 2. Navigate to the second route using Navigator.push() · 3....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found