在defaultNavigationOptions中使用Redux状态

问题描述 投票:0回答:1

我正在我的应用程序中使用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

reactjs react-native redux react-navigation
1个回答
0
投票

您可以像执行defaultNavigationOptions一样更改navigationOptions,也可以在其中访问您设置的任何参数。


defaultNavigationOptions = ({ navigationData }) => {
    let params = navigationData.navigation.state.params || {...yourDefaultParams};

    return {
        title: "MyApp",
        headerStyle: {
            backgroundColor: params["primary_color"],
        },
        headerTintColor: params["primary_color_text"],
    };
});

© www.soinside.com 2019 - 2024. All rights reserved.