Navigate from onNotification when app is killed
See original GitHub issueHello @ all,
i’m currently using the package to display local notifications which i receive via Firebase messaging. When a notification arrives in Foreground or background i’ll update my context api and display a local message. To use that i expanded the example NotifService to pass the context.
export default class NotifService {
constructor(onRegister, onNotification, context) {
this.context = context;
this.createDefaultChannels();
NotificationHandler.attachRegister(onRegister);
NotificationHandler.attachNotification(onNotification);
NotificationHandler.attachContext(context); //Added the context to the NotificationHandler
[...]
}
class NotificationHandler {
onNotification(notification) {
if (notification.userInteraction) {
if (typeof this._onNotification === 'function') {
this._onNotification(notification.data);
}
} else {
if (this._context) {
this._context.addNewNotification(notification.data); //update my context with the notification data
}
}
}
When someone clicks on the notification _onNotification is called on the Context of my HomeScreen and the user is moved to the certain screen.
The NotifService is initialized in my HomeScreen inside App.js after the context is set
static contextType = Context;
componentDidMount() {
this.notif = new NotifService(
this.onRegister.bind(this),
this.onNotif.bind(this),
this.context,
);
[...]
}
My problem is, that when the app is killed i just can receive the message via the backgroundMessageHandler of firebase in my index.js.
But at this point i dont have a context. I can initialize a new NotifService without context and the Notification will be shown, but if the notification is pressed context is undefined (because there was no context on initialize) Because of that the onNotif callback is not called and the user is not navigated to the certain screen.
Someone has an idea how i could archive that?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:11
Top GitHub Comments
What i try is to archive is to navigate to a certain screen, when a push notification is opend from “killed” state.
My configure() and onNotification is, as you and the example described, outside a component. As the notification is received in killed app state, there is no context in the notification handler. Because of this reason i can’t call “this”, because the context is undefined in killed state.
I already tried few ways, but i cant archive it.
@jailsonpaca Linking.openUrl does not work in for not-foreground notifications Could you please share detailed code or settings?