admin管理员组文章数量:1394990
I have in my app Bottom Tab Navigator version 6x. Im looking for solution how to hide a tab bar to one of screen which I use in my app - reviewDetail.js
Here is my navigation file:
AppNavigator.js
import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";
import React from "react";
import about from "../screens/about";
import home from "../screens/home";
import reviewDetails from "../screens/reviewDetails";
const Tab = createBottomTabNavigator();
const AppNavigator = () => (
<Tab.Navigator>
<Tab.Screen
name="about"
ponent={about}
options={{
title: "About",
}}
></Tab.Screen>
<Tab.Screen
name="home"
ponent={home}
options={{
title: "Home",
}}
></Tab.Screen>
<Tab.Screen name="reviewDetails" ponent={reviewDetails}></Tab.Screen>
</Tab.Navigator>
);
export default AppNavigator;
here is my app.js
App.js
import React from "react";
import { NavigationContainer, useNavigation } from "@react-navigation/native";
import AppNavigator from "./navigation/AppNavigator";
export default function App() {
return (
<>
<NavigationContainer>
<AppNavigator />
</NavigationContainer>
</>
);
}
Here is what I have:
And what I want to display:
What should I change in my code to hide "reviewDetails" tab bar? I still want to navigate to reviewDetails because I use it in my app, I only need to hide this tab bar.
I have in my app Bottom Tab Navigator version 6x. Im looking for solution how to hide a tab bar to one of screen which I use in my app - reviewDetail.js
Here is my navigation file:
AppNavigator.js
import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";
import React from "react";
import about from "../screens/about";
import home from "../screens/home";
import reviewDetails from "../screens/reviewDetails";
const Tab = createBottomTabNavigator();
const AppNavigator = () => (
<Tab.Navigator>
<Tab.Screen
name="about"
ponent={about}
options={{
title: "About",
}}
></Tab.Screen>
<Tab.Screen
name="home"
ponent={home}
options={{
title: "Home",
}}
></Tab.Screen>
<Tab.Screen name="reviewDetails" ponent={reviewDetails}></Tab.Screen>
</Tab.Navigator>
);
export default AppNavigator;
here is my app.js
App.js
import React from "react";
import { NavigationContainer, useNavigation } from "@react-navigation/native";
import AppNavigator from "./navigation/AppNavigator";
export default function App() {
return (
<>
<NavigationContainer>
<AppNavigator />
</NavigationContainer>
</>
);
}
Here is what I have:
And what I want to display:
What should I change in my code to hide "reviewDetails" tab bar? I still want to navigate to reviewDetails because I use it in my app, I only need to hide this tab bar.
Share Improve this question asked Sep 22, 2021 at 20:42 MartynBrzozMartynBrzoz 1014 silver badges11 bronze badges3 Answers
Reset to default 3If you want to hide the bottom tab for all the screens of a stack. then place the code given below to the first screen of that stack.
//For hiding tab from a certain page
useLayoutEffect(() => {
const hideUnsubscribe = navigation.addListener('focus', e => {
let parentNav = props.navigation.getParent();
parentNav.setOptions({
tabBarStyle: {display: 'none'},
});
});
}, []);
If you want to show it again then place the code given below to the screen from where the tab will be available.
//It will make the bottom tab visible
useLayoutEffect(() => {
const hideUnsubscribe = navigation.addListener('focus', e => {
let parentNav = props.navigation.getParent();
parentNav.setOptions({
tabBarStyle: {...tabBarStyle, display: 'flex'},
});
});
Note: here tabBarStyle is the main style applied to the tab bar. You need to export that style to import it here.
In react native navigati6.x on you have to use tabBarStyle: { display: 'none' }
Toggle tab bar
I don’t understand why the correct answer was marked as hiding the entire tabBar:
tabBarStyle: { display: 'none' }
If the problem was in hiding one item from the tabBar.
function AppNavigator() {
return (
<Tab.Navigator>
<Tab.Screen name='about' ponent={about} />
<Tab.Screen
name='home'
ponent={home}
options={{ tabBarStyle: { display: 'none' } }} // Hide tabBar from the screan
/>
<Tab.Screen
name='reviewDetails'
ponent={reviewDetails}
options={{ tabBarItemStyle: { display: 'none' } }} // Hide item from tabBar
/>
</Tab.Navigator>
);
}
本文标签: javascriptHow to hide a tab bar in bottom tabs navigatorReact Native 6xStack Overflow
版权声明:本文标题:javascript - How to hide a tab bar in bottom tabs navigator, React Native 6x - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744111173a2591297.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论