React native navigation v5 tab press not working
You need to listen/subscribe "tabPress" event as below in your component.
React.useEffect(() => {
const unsubscribe = navigation.addListener('tabPress', e => {
// Prevent default behavior
e.preventDefault();
// Do something manually
// ...
});
return unsubscribe;
}, [navigation]);
I found something new in documentation, that i have not seen before, this is the way to add listener to screen, every time user clicks on tab, it goes to first stack screen inside this tab
https://reactnavigation.org/docs/navigation-events/#listeners-prop-on-screen
<Tab.Screen
name="DeviceNavigatorTab"
component={DeviceNavigator}
listeners={({ navigation, route }) => ({
tabPress: e => {
if (route.state && route.state.routeNames.length > 0) {
navigation.navigate('Device')
}
},
})}
/>