I am working on a React Native project (wrapped-up using Expo) with react navigation v3. So, now I decided to enable real-time push notifications provided by Expo. My goal is to submit some custom data together with the push notification itself and then, once it goes on the device and I open the notification to navigate/route/redirect the app to a specific screen that I have defined. I have configured the notifications, I get expo tokens, I receive the notification, it goes in the handler but when I try to apply the navigation that I use throughout my whole app:
this.props.navigation.navigate('RouteName', {data:{...}})
I am getting undefined. I guess we are somehow not in the context of react navigation and that's why some other approach is required. I just don't know what it is.
The structure of my app is as follows:
HomeStack.js
import { createStackNavigator } from 'react-navigation';
import HomeScreen from '../screens/HomeScreen'
import MailboxItemsScreen from '../screens/MailboxItemsScreen'
import MailboxItemDetailsScreen from '../screens/MailboxItemDetailsScreen'
export default createStackNavigator({
Home: HomeScreen,
MailboxItems: MailboxItemsScreen,
MailboxItemDetails : MailboxItemDetailsScreen
});
SettingsStack.js
import { createStackNavigator } from 'react-navigation';
import SettingsScreen from '../screens/SettingsScreen'
export default createStackNavigator({
Settings: SettingsScreen
});
AppNavigator.js
import React from 'react';
import { createBottomTabNavigator, createAppContainer } from 'react-navigation';
import Icon from 'react-native-vector-icons/Ionicons'
import HomeStack from './HomeStack'
import SettingsStack from './SettingsStack'
const TabNavigator = createBottomTabNavigator({
Home: {
screen: HomeStack,
navigationOptions: {
tabBarIcon:({tintColor})=>(
<Icon name="ios-home" color={tintColor} size={24}/>
)
}
},
Settings: {
screen: SettingsStack,
navigationOptions: {
tabBarIcon:({tintColor})=>(
<Icon name="ios-settings" color={tintColor} size={24}/>
)
}
}
});
export default createAppContainer(TabNavigator);
Then I use the TabNavigator in my App.js. It is quite common structure I just don't know how to do the navigation between screens in my push notification handler method.