react-native - 如何在 TabNavigator 的特定屏幕上隐藏标题
问题描述
我有一个标签导航器:
const TabNav = createBottomTabNavigator({
Home: {
screen: HomeScreen,
navigationOptions: {
title: 'Home',
},
},
OtherPage: {
screen: OtherPage,
navigationOptions: {
title: 'NoHeader!',
},
},
Profile: {
screen: ProfileScreen,
navigationOptions: {
title: 'Profile',
}
},
},
{
tabBarOptions: {
activeTintColor: 'black',
style: {
backgroundColor: 'white'
},
}
});
TabNav.navigationOptions = {
title: 'Header Title',
headerRight: (
<TouchableOpacity
onPress={() => NavigationService.navigate('Rules')}
>
<Icon style={{ paddingRight: 10 }} name="ios-document" > </Icon>
</TouchableOpacity>
),
headerLeft: null,
}
export default TabNav;
我想在 OtherPage 中隐藏标题,但我需要在我的主页和个人资料页面中使用它。
我试图在 navigationOptions 中设置 header:null,但它不起作用。
有没有办法做到这一点 ?或者也许可以在堆栈导航器 headerMode:'screen' 中指定?
编辑
我尝试在每个 TabNavigator 屏幕中添加 navigationOtions,并在我的 OtherPage 中将其设置为 null,如下所示:
const TabNav = createBottomTabNavigator({
Home: {
screen: HomeScreen,
navigationOptions: {
title: 'Home',
tabBarIcon: ({ tintColor, focused }) => (
<Icon
name={focused ? 'ios-list' : 'ios-list-outline'}
size={35}
style={{ color: tintColor }}
/>
),
headerRight: (
<TouchableOpacity
onPress={() => NavigationService.navigate('Rules')}
>
<Icon style={{ paddingRight: 10 }} name="ios-document" > </Icon>
</TouchableOpacity>
),
headerLeft: null,
},
},
OtherPage: {
screen: OtherPage,
navigationOptions: {
title: 'NoHeader!',
tabBarIcon: ({ tintColor, focused }) => (
<Icon
name={focused ? 'ios-flash' : 'ios-flash-outline'}
size={35}
style={{ color: tintColor }}
/>
),
header:null
},
},
Profile: {
screen: ProfileScreen,
navigationOptions: {
title: 'Profile',
tabBarIcon: ({ tintColor, focused }) => (
<Icon
name={focused ? 'ios-person' : 'ios-person-outline'}
size={35}
style={{ color: tintColor }}
/>
),
headerRight: (
<TouchableOpacity
onPress={() => NavigationService.navigate('Rules')}
>
<Icon style={{ paddingRight: 10 }} name="ios-document" > </Icon>
</TouchableOpacity>
),
headerLeft: null,
}
},
但它也不起作用,当我这样做时,我在每个选项卡(甚至是我的 OtherPage)上都有一个默认标题(没有标题,右侧没有按钮,...)。
解决方案
不要为 TabNav 定义 navigationOtions,而是在每个 TabNavigator 屏幕中添加 navigationOtions,然后在 otherPage 中设置 header:null 即可。例如
const TabNav = createBottomTabNavigator({
Home: {
screen: HomeScreen,
navigationOptions: {
title: 'Home',
headerRight: ( <
TouchableOpacity onPress = {
() => NavigationService.navigate('Rules')
} >
<
Icon style = {
{
paddingRight: 10
}
}
name = "ios-document" > < /Icon> < /
TouchableOpacity >
),
headerLeft: null,
},
},
OtherPage: {
screen: OtherPage,
navigationOptions: {
title: 'NoHeader!',
header: null
},
},
Profile: {
screen: ProfileScreen,
navigationOptions: {
title: "Profile"
headerRight: ( <
TouchableOpacity onPress = {
() => NavigationService.navigate('Rules')
} >
<
Icon style = {
{
paddingRight: 10
}
}
name = "ios-document" > < /Icon> < /
TouchableOpacity >
),
headerLeft: null,
}
},
}, {
tabBarOptions: {
activeTintColor: 'black',
style: {
backgroundColor: 'white'
},
}
});
推荐阅读
- javascript - 您如何比较用户选择的多项选择答案并返回正确或错误的答案?
- d3.js - 如何将默认值设置为 dc selectMenu
- sql-server - 将 SQL Server 触发器转换为 Oracle 和 master.dbo.sysprocesses - 不重复
- html - 始终在包含潜水的相同位置显示工具提示
- python - cx_Freeze:主脚本中的 Python 错误 - ImportError:DLL 加载失败
- r - Kwic 函数返回“具有 0 行的 kwic 对象”,即使它不应该
- css - 结合引导导航栏和 CSS 网格
- angular - 加载 SVG 文件的内容以在 ngFor 中显示
- stripe-payments - Stripe - 向用户公开费用 ID 是否安全?
- c# - 将 MethodCallExpression 附加到属性/参数