我想有条件地从选项卡导航中隐藏一个或多个项目。从重定向页面,我发送一个布尔参数 (..navigate('SomePage', { some_value: true });) 并根据这个值,标签页项目的可见性发生变化。但是从我的研究来看,动态构建选项卡导航似乎根本没有能力。
问题
如何将项目分配给 TabNavigator?
以下是相关代码:
import X from './X'
import Y from './Y'
export const TabNavigatorTest = TabNavigator({
X: {
screen: X, navigationOptions: (props) => ({
title: "X"
})
},
Y: {
screen: Y, navigationOptions: (props) => ({
title: "Y",
})
}
},
{
navigationOptions: ({ navigation }) => ({
tabBarIcon: ({ focused, tintColor }) => {
const { routeName } = navigation.state;
let iconName;
if (routeName === 'X') {
iconName = `ios-information-circle${focused ? '' : '-outline'}`;
} else if (routeName === 'Y') {
iconName = `ios-flask${focused ? '' : '-outline'}`;
}
return <Ionicons name={iconName} size={25} color={tintColor} />;
}
}),
tabBarOptions: {
activeTintColor: 'tomato',
inactiveTintColor: 'gray',
},
tabBarComponent: TabBarBottom,
tabBarPosition: 'bottom',
removeClippedSubviews: true,
animationEnabled: true,
swipeEnabled: true,
});
....
export default class Urun extends React.Component {
...
static router = TabNavigatorTest.router;
...
render() {
...
return (
<TabNavigatorTest
navigation={this.props.navigation} />
);
}
}