gpt4 book ai didi

react-native - 如何在 TabNavigator 的特定屏幕上隐藏标题

转载 作者:行者123 更新时间:2023-12-02 03:34:05 26 4
gpt4 key购买 nike

我有一个选项卡导航器:

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,
}
},

但它也不起作用,当我这样做时,我在每个选项卡(甚至是我的其他页面)上都有一个默认标题(没有标题,右侧没有按钮,...)。

最佳答案

不要为 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'
},
}
});

关于react-native - 如何在 TabNavigator 的特定屏幕上隐藏标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50860626/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com