Is there a way to hide one item in a BottomTabNavigator? - react-native

I am building a project in react native. I want to use a bottom tab navigator, but the problem i have is that it automatically shows all screens in the navigator.
I want to hide one of the screens from the bar on the bottom.

Try this on your screen that needs to be hidden
const Tab = createBottomTabNavigator();
<Tab.Navigator>
...
<Tab.Screen
name="screen2"
component={screen2}
options={{ tabBarButton: () => null }}
/>
...
</Tab.Navigator>

Related

React Navigation Tab Screens don't show up as separate screens in history

I have a Tab Navigator with 3 screens: Home, Camera, and Profile. I then have a stack navigator which references the tab navigator, and have a screen in this stack navigator called Camera2.
const Navigation = () => {
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="Home" component={TabNavigator} />
<Stack.Screen name="Camera2" component={Camera2Screen} />
</Stack.Navigator>
</NavigationContainer>
);
};
const TabNavigator = () => {
return (
<Tab.Navigator backBehavior="history" initialRouteName="Home">
<Tab.Screen name="Home" component={HomeScreen} />
<Tab.Screen name="ToCamera" component={ToCameraScreen} />
<Tab.Screen name="Profile" component={ProfileScreen} />
</Tab.Navigator>
);
};
Suppose I start at the Home screen, then navigate to the Camera screen by selecting the camera tab. Then in the Camera screen I use navigation.replace("Camera2"). At this point, in the Camera2 screen I would want the navigation history to look like [Home, Camera2] since the Camera screen had been removed from history. However, what I end up seeing is [Camera2].
After doing some research I realized this was happening since the tab navigator acts as a single screen in the stack navigator, so seperate tabs show up as a single screen in navigation history. So if I remove the Camera screen from history it essentially removes all Tab Navigator screens (including the Home screen).
I realize this is the expected behaviour but I was wondering how I can get the desired behaviour.

React Navigation 5 : Implementing a custom header on a BottomTabNavigator

I am using a BottomTabNavigator with 2 screens but I also want to use a custom header, which I imported, to each one of them. I have tried set an option to the Tab.Navigator by adding a setOptions in it:
const Tab = createBottomTabNavigator();
export default function App() {
return(
<NavigationContainer >
<Tab.Navigator setOptions={{
headerTitle: <Header />
//</Header> was imported
}}>
<Tab.Screen
name="HomeScreen"
component={HomeScreen}
options={{
tabBarLabel: 'Home',
tabBarIcon: ({ color, size }) => (
<AntDesign name="home" color={Colors.amarelo} size={30} />
)
}}
/>
<Tab.Screen
name="GroupScreen"
component={GroupScreen}
options={{
tabBarLabel: 'Home',
tabBarIcon: ({ color, size }) => (
<AntDesign name="car" color={Colors.amarelo} size={30} />
)
}}
/>
</Tab.Navigator>
</NavigationContainer>
)
}
However, my attempt was unsuccessful. I read that docs for React-Navigation 5 but I haven't found how to implement a custom header on a BottomTabNavigator
Bottom Tab navigator does not have a header. To do this you have to use stack Navigator inside each tab of the bottom tab navigator. So you need to create a stack navigator that have "HomeScreen" as screen, same for GroupScreen. Then, in the bottom tab navigator use the stack navigators as component for tab.screen.
Than you can customize headers of bottom tab navigator.
I could post a short code if it helps you

Open drawer when clicked on bottom tab in react native

I am new in react native. I have a tab named 'Contacts' and I want to open drawer when user clicks on it. This below code opens the drawer screens when i clicked on the 'Contacts' tab. But i want to open Navigation Drawer.
Thank you so much in advance...
const Tabs = createMaterialBottomTabNavigator();
export default function bottomTab(){
return(
<NavigationContainer>
<Tabs.Navigator tabBarOptions={{activeTintColor:'#4267B2'}} >
<Tabs.Screen name="Home" component={Home} />
<Tabs.Screen name= "Contacts" component={DrawerNavigation}/>
</Tabs.Navigator>
</NavigationContainer>
)
}
const Drawer = createDrawerNavigator();
const DrawerNavigation = () => {
return(
<Drawer.Navigator>
<Drawer.Screen name="Setting" component={Setting}/>
<Drawer.Screen name="Notification" component={Notification}/>
</Drawer.Navigator>
)
}
Basically you need to use the following:
navigation.openDrawer();
If it not helping you show code of what you have already done and it will be easier to help.

React Navigation - Open Drawer from Other Tab Screen

I am using React Navigation 5 for my React Native project. I have a drawer navigator nested in tab navigator.
It looks like this:
<Tab.Navigator>
<Tab.Screen name="DrawerStack" component={DrawerStack} />
<Tab.Screen name="Screen2" component={Screen2} />
<Tab.Screen name="Screen3Stack" component={Screen3Stack} />
</Tab.Navigator>
Where DrawerStack is just a Drawer Navigator with bunch of screens.
My question is, what is the simplest way to open the drawer with a button on Screen2 or Screen3?

Middle tab button using react-navigation version 5

I need to add a middle button to the app's tab navigator.
It's easy to implement this feature using react-navigation 3, However, react-navigation 5, has a different structure and I couldn't find anyway to insert a custom button or component inside navigator.
const Tab = createBottomTabNavigator();
const TabNavigator = props => {
return (
<NavigationContainer>
<Tab.Navigator>
<Tab.Screen name="Screen1" component={FirstScreen} />
<Tab.Screen name="Screen2" component={SecondScreen} />
{...here...}
<Tab.Screen name="Screen3" component={ThirdScreen} />
<Tab.Screen name="Screen4" component={ForthScreen} />
</Tab.Navigator>
</NavigationContainer>
);
}
What can I do? Any help will be really much appreciated!
You can use the navigationOptions pros inside the Tab.screen tag and create your own custom view same as old version.