I have an issue with Drawer navigation in React Native Navigation.
The problem seems to be very simple.
I have 2 screens, on each screen I have a button that sends the user to the other one.
the problem is after sending the user from screen A to B and from B to A the button does not work anymore.
I can pull the drawer and go back to the B screen again, and the Button works there, but the button in the A screen is still frozen, the hole screen basically.
import React from "react";
import { createDrawerNavigator } from "@react-navigation/drawer";
import SettingScreen from "../screens/SettingScreen";
import ProfileScreen from "../screens/ProfileScreen";
const Drawer = createDrawerNavigator();
function MenuNavigation(props) {
return (
<Drawer.Navigator>
<Drawer.Screen name="Setting" component={SettingScreen} />
<Drawer.Screen name="Profile" component={ProfileScreen} />
</Drawer.Navigator>
);
}
export default MenuNavigation;
this is one of the screens the other one is the same with exception of names
import React from "react";
import { Button, Text, View } from "react-native";
function SettingScreen({ navigation }) {
return (
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
<Text>Hello world</Text>
<Button
title="Go to Profile Screen"
onPress={() => navigation.navigate("Profile")}
/>
</View>
);
}
export default SettingScreen;
similar to Setting Screen I have a Profile Screen, which I didn't include.
import React from "react";
import { NavigationContainer } from "@react-navigation/native";
import MenuNavigation from "./MenuNavigation";
function MainNavigation(props) {
return (
<NavigationContainer>
<MenuNavigation />
</NavigationContainer>
);
}
export default MainNavigation;
and finally, this is my package.json file and yes I'm using EXPO
{
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"eject": "expo eject"
},
"dependencies": {
"@expo-google-fonts/roboto": "^0.1.0",
"@react-native-community/checkbox": "^0.5.7",
"@react-native-community/datetimepicker": "3.0.4",
"@react-native-community/masked-view": "^0.1.10",
"@react-navigation/bottom-tabs": "^5.11.2",
"@react-navigation/drawer": "^5.12.2",
"@react-navigation/native": "^5.8.10",
"@react-navigation/stack": "^5.12.8",
"expo": "~40.0.0",
"expo-checkbox": "~1.0.0",
"expo-font": "~8.4.0",
"expo-status-bar": "~1.0.3",
"moment": "^2.29.1",
"native-base": "^2.15.2",
"react": "16.13.1",
"react-dom": "16.13.1",
"react-hook-form": "^6.14.1",
"react-native": "https://github.com/expo/react-native/archive/sdk-40.0.1.tar.gz",
"react-native-action-button": "^2.8.5",
"react-native-gesture-handler": "~1.8.0",
"react-native-modals": "^0.22.3",
"react-native-progress": "^4.1.2",
"react-native-reanimated": "^1.13.2",
"react-native-safe-area-context": "^3.1.9",
"react-native-screens": "^2.15.2",
"react-native-web": "~0.13.12",
"react-redux": "^7.2.2",
"redux": "^4.0.5",
"redux-connect": "^10.0.0",
"redux-thunk": "^2.3.0"
},
"devDependencies": {
"@babel/core": "~7.9.0"
},
"private": true
}
no Error no nothing, simply does not work.
If anyone needs more detail just ask me.
Common pattern in navigation is to use drawer from left (sometimes right) side for navigating between screens. Before continuing, first install and configure @react-navigation/drawer and its dependencies following the installation instructions.
This might occur if you have multiple versions of react-native-safe-area-context installed. If it didn't fix the error or you're not using Expo managed workflow, you'll need to check which package depends on a different version of react-native-safe-area-context .
To make this work, you need to: Disable the swipe gesture for the screen ( gestureEnabled: false ). Override the native back button in the header with a custom back button ( headerLeft: (props) => <CustomBackButton {... props} /> ).
You can also enable this behavior in React Native applications by importing the Freeze element: import { enableFreeze } from "react-native-screens"; enableFreeze(true);
React-Navigation/drawer version 5.12.3 addresses this issue:
https://github.com/react-navigation/react-navigation/releases/tag/%40react-navigation%2Fdrawer%405.12.3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With