[英]How can I hide the bottom tab bar on a specific screen (react-navigation 3.x)
I used the createBottomTabNavigator, but I can't hide the bottom app bar on a specific screen我使用了 createBottomTabNavigator,但无法隐藏特定屏幕上的底部应用栏
const StackHome = createStackNavigator(
{
Home: Home,
Autor: Autor,
Publicacion: Publicacion,
Comentarios: {
screen: Comentarios,
navigationOptions:{
// this should do the work, but it doesn't
tabBarVisible: false
}
}
}
);
Finally I got a solution that works, the component would be like this最后我得到了一个有效的解决方案,组件将是这样的
import { createStackNavigator } from "react-navigation";
import Home from "./Home";
import Autor from "./Profile";
import Publicacion from "./Publicacion";
import Comentarios from "./Comentarios";
const StackHome = createStackNavigator({
Home: Home,
Autor: Autor,
Publicacion: Publicacion,
Comentarios: Comentarios
});
// This does the trick
StackHome.navigationOptions = ({ navigation }) => {
let tabBarVisible;
if (navigation.state.routes.length > 1) {
navigation.state.routes.map(route => {
if (route.routeName === "Comentarios") {
tabBarVisible = false;
} else {
tabBarVisible = true;
}
});
}
return {
tabBarVisible
};
};
export default StackHome;
Nope, it should not... you are hidint the tab bar ... in a stacknavigator... you can do something similar to this .不,它不应该......你是hidint标签栏......在stacknavigator ...你可以做类似的东西这个。 but i don't know how you would hide it on one screen
但我不知道你会如何将它隐藏在一个屏幕上
const StackHome = createStackNavigator(
{
Home: Home,
Autor: Autor,
Publicacion: Publicacion,
Comentarios: Comentarios
}
);
StackHome navigationOptions = ({ navigation }) => {
let tabBarVisible = true;
if (navigation.state.index > 0) {
tabBarVisible = false;
}
return {
tabBarVisible,
};
};
const routesWithNoTabNavigator = ['nameOfYourRoute', 'nameOfYourOtherRoute'];
<yourStackHere>.navigationOptions = ({ navigation }) => {
let tabBarVisible = true;
const currentRoute =
navigation.state.routes[navigation.state.routes.length -1].routeName;
if(routesWithNoTabNavigator.includes(currentRoute)) {
tabBarVisible = false;
}
return {
tabBarVisible,
};
};
if your screen is also nested stack navigation and the parent is a bottom navigation, there is a navigation prop on options function you can use.如果您的屏幕也是嵌套的堆栈导航并且父级是底部导航,则您可以使用选项功能上的导航道具。 eg:
例如:
const BottomTab = createBottomTabNavigator();
const Home = () => (
<BottomTab.Navigator
initialRouteName="Explore"
tabBarOptions={{
activeTintColor: "#00B0F0",
}}
>
<BottomTab.Screen
name="Explore"
component={Explore}
options={({ navigation }) => {
const { routes, index } = navigation.dangerouslyGetState();
const { state: exploreState } = routes[index];
let tabBarVisible = true;
if (exploreState) {
const { routes: exploreRoutes, index: exploreIndex } = exploreState;
const exploreActiveRoute = exploreRoutes[exploreIndex];
if (exploreActiveRoute.name === "RewardDetail") tabBarVisible = false;
}
return {
tabBarVisible,
title: "Explore",
tabBarLabel: "Explore",
tabBarIcon: ({ color, size }) => (
<AntDesign name="search1" color={color} size={size} />
),
};
}}
/>
note that you will have to use if conditions there as props are not present when not activated, just simply do as my example.请注意,您将不得不使用 if 条件,因为在未激活时不存在道具,只需按照我的示例进行操作即可。 There is also a suggestion from the documentation: https://reactnavigation.org/docs/hiding-tabbar-in-screens/ personally i would do that if there's no option for tabBarVisible usage.
文档中还有一个建议: https ://reactnavigation.org/docs/hiding-tabbar-in-screens/ 如果没有 tabBarVisible 使用选项,我个人会这样做。
Do like this:这样做:
if(navigation.state.routes[navigation.state.index].routeName == "Comentarios"){
tabBarVisible = false;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.