Hiding header in bottom tab navigator not working - react-native

I have a react native expo app with a bottom tab navigator. How do I hide a specific screen header?
Here is my code:
export default function MainContainer() {
const Tab = createBottomTabNavigator();
const {toggleColorMode} = useColorMode();
const settings = {bg: useColorModeValue("white", "muted.800")};
return (
<NavigationContainer>
<Tab.Navigator screenOptions={{headerShown: false}}>
<Tab.Screen name="Home" children={() => <Home settings={settings}/>}/>
<Tab.Screen name="Test" children={() => <Test settings={settings}/>}/>
<Tab.Screen name="Result" children={() => <Result settings={settings}/>}
options={{headerShown: false}}/>
<Tab.Screen name="Training" children={() => <Training settings={settings}/>}/>
<Tab.Screen name="History" children={() => <History settings={settings}/>}/>
<Tab.Screen name="Stats" children={() => <Stats settings={settings}/>}/>
<Tab.Screen name="Settings"
children={() => <Settings darkMode={toggleColorMode} settings={settings}/>}/>
</Tab.Navigator>
</NavigationContainer>
);
}
As you can see, I tried to use options={{headerShown: false}} and screenOptions={{headerShown: false}} but it just doesn't work for some reason.
Do you know what could be causing this problem and how to solve it?
Note that I removed unnecessary lines of code and rewrote some words to english, so the code itself might not work, but the code works fine except for the header hiding.

At navigator level hide a header for all screens and show for certain at screen level
<Tab.Navigator screenOptions={{headerShown: false}}>
<Tab.Screen options={{headerShown: true}} name="Home" component={HomeScreen} />
<Tab.Screen name="Settings" component={SettingsScreen}/>
</Tab.Navigator>
or just hide for certain at screen level
<Tab.Navigator>
<Tab.Screen name="Home" component={HomeScreen} />
<Tab.Screen options={{headerShown: false}} name="Settings" component={SettingsScreen}/>
</Tab.Navigator>
and in both cases a header is hidden for Settings screen.

Related

What's the correct approach for having a list/detail view with React Native Navigation Bottom Tab?

I have something like:
const Tab = createBottomTabNavigator<DefaultTabbedParamList>();
const DefaultTabbedNavigation = () => {
return (
<>
<Tab.Navigator initialRouteName='Home' screenOptions={{
unmountOnBlur: true,
}}>
<Tab.Screen name="Home" component={HomeScreen} options={{
...defaultOptions,
tabBarIcon: ({ color, size, focused }) => (
<Icon as={Ionicons} name={`home${focused ? `` : `-outline`}`} size={size} color={color} />
)
}} />
...
</Tab.Navigator>
</>
);
}
When a user clicks to a detail view from Home (or any other tab), I want to load a detail view with the currently selected tab remaining.
What's the correct approach to handle this?
One idea I had was to have a StackNavigator in HomeScreen that includes a Detail screen. But it seems repetitive to do for every screen, no?
You can do something like this :-
<Tab.Navigator initialRouteName='Home' screenOptions={{
unmountOnBlur: true,
}}>
<Tab.Screen name="Home" component={HomeScreen} options={{
...defaultOptions,
tabBarIcon: ({ color, size, focused }) => (
<Icon as={Ionicons} name={`home${focused ? `` : `-outline`}`} size={size} color={color} />
)
}} />
// Something like this.
<Tab.Screen name="Home2" children={({route}) => <route?.name />} ...{otherProperties}/>
...
</Tab.Navigator>
Note:- To use this kind of approch your routeName and componentName should be same.
How about this?
return (
<NavigationContainer>
<Stack.Navigator screenOptions={{ headerShown: false }}>
<Stack.Screen name={"Tabs"} component={Tabs} />
<Stack.Screen name={"Detail"} component={DetailScreen} />
</Stack.Navigator>
</NavigationContainer>
);
Yeah, you'll likely want to define a StackNavigator for each tab. It's a bit repetitive, but that's been a theme of my experience with RN.
You can do something like:
const HomeStackNavigator = () => {
return (
<Stack.Navigator>
<Stack.Screen name="Home" component={HomeScreen} />
<Stack.Screen name="Detail" component={DetailScreen} />
</Stack.Navigator>
);
};
const OtherStackNavigator = () => {
return (
<Stack.Navigator>
<Stack.Screen name="Other" component={OtherScreen} />
<Stack.Screen name="Detail" component={DetailScreen} />
</Stack.Navigator>
);
};
const DefaultTabbedNavigation = () => {
return (
<Tab.Navigator>
<Tab.Screen name="Home" component={HomeStackNavigator} />
<Tab.Screen name="Other" component={OtherStackNavigator} />
</Tab.Navigator>
)
}

How do I go from the screen in the navigator to the screen in the other navigator?

function Logins() {
return (
<Provider theme={theme}>
<Stack.Navigator
initialRouteName="StartScreen"
screenOptions={{
headerShown: false,
}}
>
<Stack.Screen name="StartScreen" component={StartScreen} />
<Stack.Screen name="LoginScreen" component={LoginScreen} />
<Stack.Screen name="RegisterScreen" component={RegisterScreen} />
<Stack.Screen name="Dashboard" component={Dashboard} />
<Stack.Screen
name="ResetPasswordScreen"
component={ResetPasswordScreen}
/>
</Stack.Navigator>
</Provider>
)
}
function Drawers() {
return (
<Drawer.Navigator>
<Drawer.Screen name="Profile" component={UnderConstruction} />
<Drawer.Screen name="Popular" component={UnderConstruction} />
<Drawer.Screen name="Saved" component={UnderConstruction} />
<Drawer.Screen name="Discover" component={UnderConstruction} />
<Drawer.Screen name="Configuration" component={UnderConstruction} />
<Drawer.Screen name="Help Center" component={UnderConstruction} />
</Drawer.Navigator>
)
}
function Main() {
return (
<Stack.Navigator initialRouteName="Home">
<Stack.Screen name="Home" component={Home} />
<Stack.Screen name="Search" component={Search} />
<Stack.Screen name="Notification" component={Notification} />
<Stack.Screen name="Message" component={Message} />
</Stack.Navigator>
)
}
function Detail() {
return (
<Stack.Navigator>
<Stack.Screen name="Tweet" component={UnderConstruction} />
<Stack.Screen name="New Tweet" component={TweetButton} />
<Stack.Screen name="New Message" component={UnderConstruction} />
<Stack.Screen name="DynamicTitle" component={UnderConstruction} />
</Stack.Navigator>
)
}
export default function App() {
return (
<NavigationContainer>
<Stack.Navigator
initialRouteName="Logins"
screenOptions={{
headerMode: 'none',
}}
>
<Stack.Screen name="Logins" component={Logins} />
<Stack.Screen name="Main" component={Main} />
<Stack.Screen name="Drawer" component={Drawers} />
<Stack.Screen name="Details" component={Detail} />
</Stack.Navigator>
</NavigationContainer>
)
}
As you can see, I made a stack navigator that contains all the stack navigators, logins, main, drawers, and details.
And I want to make it possible to move between Home and New Tweet, which belong to different navigators.
I tried this.props.navigation.navigate ("New Tweet")
and this.props.navigation.navigate ("Details", {screen: "New tweet"}) inside the components on the Home screen.
But both didn't work and I got an error "NAVIGATE" with payload {"name": "New tweet"} was not handled by any navigator.
I think it's because they're different navigators. But I don't know how to do..
Change Detail to Details and New tweet to New Tweet. Try following
this.props.navigation.navigate ("Details", {screen: "New Tweet"})
I think there is no way directly to switch to a different stack navigator if they are not related to each other. From here I think this can be one option
Make the screen available in the stack that you want to switch from the home screen. For example, in the main function, if you want to switch to "detail" screen
function Main()
{
return (
<Stack.Navigator initialRouteName="Home">
<Stack.Screen name="Home" component={Home} />
<Stack.Screen name="Search" component={Search} />
<Stack.Screen name="Notification" component={Notification} />
<Stack.Screen name="Message" component={Message} />
<Stack.Screen name="Details" component={Detail} />
</Stack.Navigator>)
}
now from here your homescreen you can call this.props.navigation.navigate ("Details", {screen: "New Tweet"})
You can also look into the below thread to achieve this otherway around
React Navigation 5: Switching between different stack navigators in React native

How to enable Drawer Navigation only on specific screen (e.g. Home Screen) [react native] [react navigation]

Use case of this problem is to have Drawer menu like "Settings" available only form "Home Screen". And at "Home screen" could be many buttons that link to other screens of Stack Navigation where Drawer is not available.
Main question is how to enable Drawer Navigation only on specific screen of Stack Navigator?
On below example Drawer is available on all pages of Stack. I tried with gestureEnabled but it didn't work:
const StackHome = () => (
<Stack.Navigator>
<Stack.Screen name="Home" component={Home} />
<Stack.Screen name="Example1" component={Example1} />
<Stack.Screen name="Example2" component={Example2} />
</Stack.Navigator>
);
<Drawer.Navigator initialRouteName="Home">
<Drawer.Screen name="Home" component={StackHome} />
<Drawer.Screen name="Settings" component={Settings} />
</Drawer.Navigator>
On the other hand if I try make Drawer as one of Stack screen, then I have always the same Header bar (example "Header")
Put your drawer navigator inside the home screen:
const DrawerHome = () => (
<Drawer.Navigator screenOptions={{ headerShown: true }}>
<Drawer.Screen name="Home" component={Home} />
<Drawer.Screen name="Settings" component={Settings} />
</Drawer.Navigator>
);
const StackHome = () => (
<Stack.Navigator>
<Stack.Screen
name="DrawerHome"
component={DrawerHome}
options={{ headerShown: false }}
/>
<Stack.Screen name="Example1" component={Example1} />
<Stack.Screen name="Example2" component={Example2} />
</Stack.Navigator>
);

How to hide top navigation bar in react native

I need to hide nav bar on top in specific screens. How to achieve?. i am using react-navigation/material-top-tabs
I need to hide nav bar on top in specific screens. How to achieve?. i am using react-navigation/material-top-tabs
I need to hide nav bar on top in specific screens. How to achieve?. i am using react-navigation/material-top-tabs
//page 1 <Stack.Navigator headerMode="none" initialRouteName="Connection">
<Stack.Screen
name="Connection"
component={UserScreen}
options={{ unmountOnBlur: true }}
/>
</Stack.Navigator>
//page2 <Tab.Navigator
// screenOptions={{ tabBarVisible: false }}
// screenOptions={({ route }) => ({
// tabBarVisible: false,
// })}
initialRouteName="UserTabStack"
tabBarOptions={{
labelStyle: {
fontWeight: "bold",
},
indicatorStyle: {
backgroundColor: "black",
},
}}
>
<Tab.Screen
name="UserTabStack"
// component={UserList}
component={UserTabStack}
options={{ tabBarLabel: "Userlist" }}
listeners={({ route }) => {
setTabPage(route.name);
}}
/>
<Tab.Screen
name="GroupList"
// component={GroupList}
component={GroupTabStack}
options={{ tabBarLabel: "GroupList" }}
listeners={({ route }) => {
setTabPage(route.name);
}}
/>
</Tab.Navigator> //page3 <Stack.Navigator headerMode="none" initialRouteName="UserList">
<Stack.Screen
name="UserList"
component={UserList}
options={{ unmountOnBlur: true }}
/>
<Stack.Screen
name="AddConnection"
component={AddUserScreen}
options={{ unmountOnBlur: true }}
/>
<Stack.Screen
name="Chat"
component={ChatScreen}
options={{ unmountOnBlur: true }}
/>
</Stack.Navigator>
set headerShown to false in Stack.Screen options
<Stack.Screen
name="UserList"
component={UserList}
options={{ unmountOnBlur: true, headerShown: false }}
/>
Per the React Navigation Docs, you can hide the tab bar on specific screens by changing your navigation structure. In their example:
function HomeTabs() {
return (
<Tab.Navigator>
<Tab.Screen name="Home" component={Home} />
<Tab.Screen name="Feed" component={Feed} />
<Tab.Screen name="Notifications" component={Notifications} />
</Tab.Navigator>
);
}
function App() {
return (
<Stack.Navigator>
<Stack.Screen name="Home" component={HomeTabs} />
<Stack.Screen name="Profile" component={Profile} />
<Stack.Screen name="Settings" component={Settings} />
</Stack.Navigator>
);
}
The tab navigator is inside the first screen, and is the first component in your app's navigator. The following components are the two components that you don't want the top bar to be shown on, so in this example, Settings and Profile.

Remove header on createMaterialTopTabNavigator

how do I remove the header on createMaterialTopTabNavigator()?
I've looked everywhere, including the documentation. So far I've only seen examples
which are relevant to the previous version.
Here's my code:
<NavigationContainer headerMode='none'>
<Tab.Navigator options={{ headerShown: false }}>
<Tab.Screen name="Home" component={Home}/>
<Tab.Screen name="Settings" component={Settings}/>
</Tab.Navigator>
</NavigationContainer>
EDITED
HeaderShown option is for screens, not navigator. So replace by this
const IndexStack = createStackNavigator()
const index = () => {
return(
<IndexStack.Navigator initialRouteName="tabNav">
<IndexStack.Screen name="tabNav" options={{ headerShown: false }} component={tabNav} />
</IndexStack.Navigator>
)
}
const tabNav = () => {
return(
<NavigationContainer>
<Tab.Navigator>
<Tab.Screen name="Home" component={Home} />
<Tab.Screen name="Settings" component={Settings} />
</Tab.Navigator>
</NavigationContainer>
)
}