android - 在 React Native 的特定屏幕中隐藏 TabBar
问题描述
我一直在尝试在特定屏幕中隐藏 tabBar,尝试了一些解决方案,但没有一个对我有用(使用 Native-Base)用于 UI。
我有一个 TabNavigator,我在其中传递了一个带有屏幕的堆栈。
所以我想要做的是在其中一个屏幕中隐藏 TabBar。请参阅下面的代码。
import React from 'react';
import {createBottomTabNavigator} from '@react-navigation/bottom-tabs';
import {createStackNavigator} from '@react-navigation/stack';
import { NativeBaseProvider } from 'native-base';
const Tab = createBottomTabNavigator();
const Stack = createStackNavigator();
//Stack of Screens linked with the search Menu.
function Recherche() {
return (
<Stack.Navigator initialRouteName="Recherche">
<Stack.Screen
name="Recherche"
component={Search}
options={{title: 'Recherche', headerShown: false}}
/>
<Stack.Screen
name="ViewCarte"
component={ViewCarte}
options={{title: 'ViewCarte', headerShown: false}}
/>
</Stack.Navigator>
);
}
//Stack of Screens linked with the Mon Espace Menu.
function MonEspace() {
return (
<Stack.Navigator initialRouteName="Espace">
<Stack.Screen
name="Espace"
component={Espace}
options={{title: 'Espace', headerShown: false}}
/>
<Stack.Screen
name="Compte"
component={Compte}
options={{title: 'Compte', headerShown: false}}
/>
</Stack.Navigator>
);
}
//Function constructing the TabBar
function ViewLoc({navigation}) {
return (
<NativeBaseProvider>
<Tab.Navigator
initialRouteName="Recherche"
tabBarOptions={{
activeTintColor: '#0B3D91',
style: {
padding: 5,
height: 60,
},
tabStyle: {
paddingTop: 8,
paddingBottom: 8,
},
}}>
<Tab.Screen
name="Recherche"
component={Recherche}
options={{
tabBarIcon: ({color, size}) => (
<SearchIcon color={color} size={size} />
),
}}
/>
<Tab.Screen
name="Mon espace"
component={MonEspace}
options={{
tabBarIcon: ({color, size}) => <ProfileIcon color={color} />,
tabBarVisible: true,
}}
/>
</Tab.Navigator>
</NativeBaseProvider>
);
}
试图在屏幕“ViewCarte”和屏幕“Compte”中隐藏 tabBar。
解决方案
你可以改变导航结构,你的结构应该是这样的
const RootStack = createStackNavigator();
const Tab = createBottomTabNavigator();
function TabsNavigatorComponent() {
return (
<Tab.Navigator>
//any screen or stack here will show with tabs.
</Tab.Navigator>
)
}
<NavigationContainer>
//the main Navigator shoud be Stack
<RootStack.Navigator>
//outside any screen to here, to show it without tabs.
<RootStack.Screen name="screenWithoutTabs" component={ScreenWithoutTabs}/>
<RootStack.Screen name="bottomTabs" component={TabsNavigatorComponent}/>
</RootStack.Navigator>
</NavigationContainer>
推荐阅读
- python - 无法获取单个 mongo 文档
- git - 我可以回滚到之前的时间点,然后在 Android Studio 3.5.1 中使用 GitHub 回来吗?
- c# - RabbitMQ consuming one message before receiving a new
- powershell - Powershell下拉选择项,将特定文本文件加载到表单上的文本框中
- numpy - 从自反不对称传递关系中删除不必要的对
- python - 如何使用python更改图像的相机型号名称
- highcharts - 通过在 Highcharts 中下载为 pdf 来更改数据
- c# - 如何创建双行列表 [,]
- python - Python 3.8 ModuleNotFoundError:没有名为“PIL”的模块
- kibana-7 - 在 Kibana 可视化中使用过滤器获得热门