I'm using the useNavigation hook from @react-navigation/native to toggle a drawer when pressing a button. The following code works perfectly for me:
import { useNavigation } from '@react-navigation/native';
import { TouchableOpacity } from 'react-native';
import Ionicons from 'react-native-vector-icons/Ionicons';
const MyComponent = () => {
const navigation = useNavigation();
return (
<TouchableOpacity onPress={() => navigation.toggleDrawer()}>
<Ionicons name="menu" size={30} color="#fff" />
</TouchableOpacity>
);
};
This successfully opens the drawer when the button is pressed. If anyone is facing similar issues, I hope this helps! Feel free to reach out if you have any questions or need clarification.