我相对确定我发现这是不可能的,但我想确保没有办法。
有问题的应用程序以 AppNavigator 开始StackNavigator
。
export const AppNavigator = StackNavigator({
Login: {
screen: Login,
navigationOptions: ({navigation}) => ({
title: 'Aanmelden',
params: {
nuke: navigation.state.params && !!navigation.state.params.nuke,
},
}),
},
Main: {
screen: DynamicTabBar,
navigationOptions: ({navigation}) => ({
title: 'Follow-up',
}),
},
}, {
mode: 'modal',
headerMode: 'none',
});
export class AppWithNavigationState extends React.Component {
constructor(props) {
super(props);
}
render() {
return <AppNavigator navigation={addNavigationHelpers({ dispatch: this.props.dispatch, state: this.props.navigationReducer })} />
}
}
AppWithNavigationState.propTypes = {
dispatch: React.PropTypes.func.isRequired,
navigationReducer: React.PropTypes.object.isRequired,
};
const mapStateToProps = state => ({
navigationReducer: state.navigationReducer,
});
export default connect(mapStateToProps)(AppWithNavigationState);
到目前为止一切顺利,只是DynamicTabBar
在用户登录之前不应该“渲染”(即从导航Login
到Main
)。
这就是为什么
const Tabs = TabNavigator({
Start: {
screen: UserStackNavigator,
navigationOptions: {
tabBarIcon: (<Icon
type="font-awesome"
name="users"
color="#dddddd"
size={20}
/>),
},
},
...Account.User.CanEnter ? {
ConditionalTab: {
screen: ConditionalScreen,
navigationOptions: {
tabBarIcon: (<Icon
type="font-awesome"
name="recycle"
color="#dddddd"
size={20}
/>),
},
}} : {},
Settings: {
screen: Settings,
navigationOptions: {
tabBarIcon: (<Icon
type="font-awesome"
name="cog"
color="#dddddd"
/>),
}
}
},{
...TabNavigator.Presets.AndroidTopTabs,
tabBarPosition: "bottom",
tabBarOptions: {
activeTintColor: '#eaeb65',
showIcon: true,
showLabel: false,
style: { backgroundColor: '#333' },
}
});
export default class DynamicTabBar extends React.Component {
constructor(props) {
super(props);
}
render() {
return <Tabs navigation={this.props.navigation} />;
}
}
DynamicTabBar.router = Tabs.router;
...Account.User.CanEnter ? {
始终为 false,因为在用户登录并填充TabNavigator
之前呈现。Account
一次失败的尝试,它接缝了。
我想在Tabs
里面填充componentWillMount
,但是我不能设置静态路由器:DynamicTabBar.router = Tabs.router;
有想法该怎么解决这个吗?