I've created a react-native app that uses Expo and React navigation. For the menu I am using the react navigation drawer.
Minimalistic code example:
import * as React from 'react';
import { View, Text } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createDrawerNavigator } from '@react-navigation/drawer';
import { useWindowDimensions } from 'react-native';
function Feed() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Feed Screen</Text>
</View>
);
}
function Article() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Article Screen</Text>
</View>
);
}
const Drawer = createDrawerNavigator();
function MyDrawer() {
const dimensions = useWindowDimensions();
return (
<Drawer.Navigator
screenOptions={{
drawerType: dimensions.width >= 768 ? 'permanent' : 'front',
drawerStyle: {
backgroundColor: '#c6cbef',
width: 240,
},
}}
>
<Drawer.Screen name="Feed" component={Feed} />
<Drawer.Screen name="Article" component={Article} />
</Drawer.Navigator>
);
}
export default function App() {
return (
<NavigationContainer>
<MyDrawer />
</NavigationContainer>
);
}
{
"name": "my-app",
"version": "1.0.0",
"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": {
"@react-navigation/drawer": "^6.1.8",
"expo": "~44.0.0",
"expo-status-bar": "~1.2.0",
"react": "17.0.1",
"react-dom": "17.0.1",
"react-native": "0.64.3",
"react-native-gesture-handler": "~2.1.0",
"react-native-reanimated": "~2.3.1",
"react-native-web": "^0.17.1"
},
"devDependencies": {
"@babel/core": "^7.12.9"
},
"private": true
}
CodePudding user response:
This is a bug in the react-navigation library itself and there is already an open issue about it. Upvote the bug on GitHub and keep tracking it there.
https://github.com/react-navigation/react-navigation/issues/8551
CodePudding user response:
I was expecting an issue in how I used the code but it appears to be a bug in React Navigation.
Instead of using permanent/back, I am now using permanent/front and the issue won't appear. Good enough for now as a work-around. Alternative is to fallback on version 6.1.4.
<Drawer.Navigator
screenOptions={{
drawerType: dimensions.width >= 768 ? 'permanent' : 'front',
drawerStyle: {
backgroundColor: '#c6cbef',
width: 240,
},
}}
>
See the issue tracker of React Navigation for the latest status: https://github.com/react-navigation/react-navigation/issues/10044

