I have a case, i got a remote notification in payload i have some data I want to pass to a specific screen.
Now
in home screen, I add a listener to listen when notification oped to get the payload well?
now in the payload itself, I got a name to tell me where should i navigate
Like this
username: "oliver"
screenType: "new_chat"
user_id: 21
Now as i say before i have listener when opened notification i check for screenType to decide where i navigate
const onOpened = (openResult) => {
let {
screenType,
username,
user_id,
} = openResult.notification.payload?.additionalData;
switch (screenType) {
....
case 'new_chat':
setTimeout(() => {
navigation.navigate('Messages', {
screen: 'MessagesListScreen',
params: {
from: 'notification',
userIDWithoutPrefix: user_id,
userSender: username,
},
});
}, 2000);
break;
....
default:
break;
}
};
When i open the notification its navigate me to MessagesListScreen
and it navigates me well
but when i log the params I got undefined
!
React.useEffect(() => {
const unsubscribe = navigation.addListener('focus', () => {
console.log('hey focus', route); // key,name well but params undefined
if (fromScreen === 'notification') {
console.log('yes if here');
setTimeout(() => {
navigation.navigate('ChatScreen', {
userIDWithoutPrefix: userIDWithoutPrefix,
userSender: userSender,
});
}, 500);
} else {
console.log('No go out', route.params); // undefined
}
});
return unsubscribe;
}, [navigation]);
Does anyone have an explanation to this case?