Bottom Tabs in Drawer Navigator - react-native

I read the documentation of react-navigation to create drawer and tab navigator.
The drawer is good but the tab navigator does not meet my need.
I wish a bottom tab navigation was a shorcut to drawer menu and it should be displayed to all other screen.
Drawer menu I have :
Menu A / Menu B / Menu C / Menu D
And in a bottom tab I don't want new screen navigation but just a shortcut navigation to Menu A and Menu D.
I managed to initiate what I wish with this
<>
<Drawer.Navigator>
<Drawer.Screen ...>
<Drawer.Screen ...>
</Drawer.Navigator />
<CustomBottomNavigation />
</>
The CustomBottonNavigation use BottomNavigation of react-native-paper.
Work fine but the drawer menu does not pass in front of the bottom navigation (expected implementation behaviour)
So my question, is a better way to do this ?
I search about a way to pass a component that should be displayed to all drawer screen but react-navigation drawer don't have a param to do this (to my knowledge).

Related

How do you disable swipe to open drawer navigator, but keep swipe to navigate back?

I'm in this situation where I have a screen in a drawer navigator that I want to be able to swipe right to navigate back to the previous screen. But since it's in a drawer navigator, my right swipe opens the drawer and I am unable to navigate back without pressing the back arrow. Is there a way to disable to drawer swipe for that screen, but keep the swipe to navigate. Any help is appreciated. TYIA
You need disable swipe to open/close drawer with swipeEnabled prop in screenOptions, like:
<Drawer.Navigator
screenOptions={{
// ... defined something
swipeEnabled: false,
}}>
// ... your drawer
</Drawer.Navigator>
And you need define a drawer item in 1 stack be like my example: https://snack.expo.dev/#pqv2210/q-74710170
// Solution 1
**React Navigation 6**
In screen options: Set edge width to 0.
<Drawer.Navigator
screenOptions={{
swipeEdgeWidth: 0,
}}
>
{/* screens */}
</Drawer.Navigator>
**React Navigation 5**
In your createDrawerNavigator config:
const drawerNavigator = createDrawerNavigator({
Home: {
screen: Home
}
},
{
edgeWidth: 0
})
//Solution 2 : This may also work.
You can use the drawerLockMode in the screen navigation options using the option locked-open
locked-open: the drawer will stay opened and not respond to gestures. The drawer may still be opened and closed programmatically
Other options can be viewed here
static navigationOptions = {
drawerLockMode: 'locked-open',
}

expo react-navigation 5.x, Bottom Tab Navigator works differently on IOS and Android when wrapped in Drawer Navigator

wanted to implement Bottom Tab Navigator with a Custom Styled Central Tab Icon and a DrawerNavigator. When the BottomTab is wrapped with DrawerNavigator, the Center Button that has roundness gets clipped on Android (ok on IOS)
For Android
For IOS it is fine, with or without Drawer wrap
A working snack of above is below to toggle both states (with DrawerNavigator + Bottom Navigator Vs Bottom Navigator)
Again issue is only on Android
https://snack.expo.dev/#haniq313/bottomtab-custom-center-icon
The issue is not there with react-navigation 6.x. But need to make this work on React-Navigation 5.x
https://github.com/react-navigation/react-navigation/issues/9615
for this looking for a solution. It is a known bug in navigation 5.x and as metioned can be fixed by Wrapping the whole Tab.Navigator in a
<Pressable style={{ flex: 1, }} disabled > <Tab.Navigatior> ......... </Tab.Navigator>

React Navigation + React Native Web - Navigating to same screen multiple times in drawer navigator does not add to browser history

I am using React Navigation v5 with React Native Web to create a chat UI similar to Slack, Discord, Messages for Web, etc. I'm using Drawer Navigator with custom drawer content containing links to a Chat screen passing a param for the chat ID. Using linking on the NavigationContainer, clicking each link changes the browser URL to /chat/:id. The problem I am facing is that each navigation to a different chat URL does not add to the browser history, so using the browser back button navigates the user wherever they were before clicking the first chat URL - they are not able to use the browser back button to cycle back through their previously selected chats.
I suspect this is related to how navigation.navigate() reuses an existing screen if you navigate to the same screen with different params (source). An alternative might be to use navigation.push(), but I haven't been able to get this working within a drawer context and would also hesitate to keep pushing new screens onto the stack as the user is navigating back and forth between different chats.
Example of my drawer navigator:
<Drawer.Navigator
openByDefault
drawerType='permanent'
drawerContent={props => <DrawerContent {...props />}
>
<Drawer.Screen name="Landing" component={LandingScreen} />
<Drawer.Screen name="Chat" component={ChatScreen} />
</Drawer.Navigator>
Within DrawerContent, there is a FlatList of chat items, each with an onPress handler such as:
const onPress = (chatId) => {
navigation.navigate('Chat', {id: chatId});
};
The drawer navigator itself is a screen within a Stack Navigator:
<Stack.Navigator>
<Stack.Screen name="Chats" component={ChatNavigator} />
<Stack.Screen name="Settings" component={Settings} />
</Stack.Navigator>
Anyone have any advice on this approach? Is there a way I can use the existing behaviour of the drawer navigator on web while being able to navigate to the same screen multiple times with different params with full browser history support?

Drawer Navigator render below status bar (margin top) [React Navigation]

I'm using React Navigation and I have a DrawerNavigator and I want the drawer to be below the status bar. This is an example:
In the drawer configuration I have setted a contentComponent with a View inside, I tried changing the view height, margin, top, etc por the View is actually inside the drawer so it doesn't affect the white box.
I know It's late now but may some others can take benefit from this.
<DrawerContentScrollView {...props} contentContainerStyle={{paddingTop: 10}}>
contentContainerStyle property has by default some paddingTop so you can over right.
Thanks

How to use a custom component to the tab bar navigator?

I need to use the Tab navigator but need to customize its tab bar. Here's what I'm trying to achieve:
The middle button is not a screen in the tab bar. It's a custom button which opens a floating menu. Now I have already created this component but unable to attach it to my tab bar. All I want to do is to navigate to screens through this tab bar.
The app's code looks like this:
<View style={{ flex: 1, backgroundColor: '#f3f3f3' }}>
<MainTabNavigator /> // The tabbar created from react-navigation
<TabBar navigation={tabNavigation} /> // My custom tabbar
</View>
I tried to use the NavigationActions navigate function. It didn't work. I tried to pass the navigation props from a tab screen to my redux store, pass it back to my custom tab bar and used it's navigating function. The function gets passed but nothing happens. Yes, the last thing I did is a bit stupid. Can anyone please help me fix this?