gpt4 book ai didi

javascript - React Navigation如何从堆栈导航内部隐藏标签栏

转载 作者:行者123 更新时间:2023-12-04 11:06:03 24 4
gpt4 key购买 nike

我有以下堆栈导航和屏幕:

export const HomeStack = createStackNavigator({
Home: HomeScreen,
Categories: CategoriesScreen,
Products: ProductsScreen,
ProductDetails: ProductDetailsScreen,
})
我只想在 ProductDetailsS​​creen 中隐藏标签:
export const hideTabBarComponents = [
'ProductDetails',
]

export const MainTabs = createBottomTabNavigator(
{
Home: HomeStack,
Favorite: FavoriteScreen,
Account: AccountScreen,
Help: HelpScreen,
Events: EventsScreen
},
{
navigationOptions: ({ navigation }) => ({

tabBarIcon: ({ focused, tintColor }) => {
...
},
tabBarLabel: ({ focused, tintColor }) => {
...
},

tabBarVisible: ! hideTabBarComponents.includes(navigation.state.routeName)

}),
}
);
问题是无法从堆栈导航将任何选项传递给选项卡导航
并非所有堆栈屏幕都只有其中一个

最佳答案

下面的代码解决了这个问题:

HomeStack.navigationOptions = ({ navigation }) => {

let tabBarVisible = true;

let routeName = navigation.state.routes[navigation.state.index].routeName

if ( routeName == 'ProductDetails' ) {
tabBarVisible = false
}

return {
tabBarVisible,
}
}

关于javascript - React Navigation如何从堆栈导航内部隐藏标签栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51352081/

24 4 0