我正在我的应用程序中使用React-navigation和redux。
我必须根据状态更改标题颜色。我已经保存了内部状态的颜色,而我的颜色来自于Api调用。
根据文档,我已经使用了带有redux的navigationOptions。
static navigationOptions = ({ navigation }) => ({
title: "MyApp",
headerStyle: {
backgroundColor: navigation.getParam('primary_color'),
},
headerTintColor: navigation.getParam('primary_color_text')
})
componentWillMount() {
this.props.navigation.setParams({
...this.props.appSettings
});
}
但是由于参数设置了道具,所以我得到白色标头的时间为1秒,然后是我的颜色的颜色为1秒。那有什么办法可以连接defaultNavigationOptions
?
您可以像执行defaultNavigationOptions
一样更改navigationOptions
,也可以在其中访问您设置的任何参数。
defaultNavigationOptions = ({ navigationData }) => {
let params = navigationData.navigation.state.params || {...yourDefaultParams};
return {
title: "MyApp",
headerStyle: {
backgroundColor: params["primary_color"],
},
headerTintColor: params["primary_color_text"],
};
});