I want to execute a certain code whenever a drawer element is clicked.
In other words, I am looking for a drawer equivalent to the property tabPress.
I tried adding my callback to the property focus. However, this callback is executed whenever "any screen" in the relevant stack is "in focus."
I want the code to be exuted only if the user "clicks" on a "drawer item". Is this at all possible?
import { createDrawerNavigator } from "@react-navigation/drawer";
const MyNav = createDrawerNavigator();
<MyNav.Navigator>
<MyNav.Screen name="abc" component={abcStack}
listeners={ ({ navigation, route }) => ({
// This is executed whenever any screen in the stack is accessed. This does NOT satisfy my requirements.
focus: (e) => {
console.log("We are in focus");
},
// Is there something like "tabPress" for Drawer stacks?
tabPress: (e) => {
console.log("We are on tabPress");
},
})}
/>
</MyNav.Navigator>
This question is related to React-Navigation Version 6.