Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css react native中redux存储的动态样式_Css_React Native_Redux - Fatal编程技术网

Css react native中redux存储的动态样式

Css react native中redux存储的动态样式,css,react-native,redux,Css,React Native,Redux,我想在react原生应用程序中使用动态css样式。目前我使用的css样式来自一个文件,比如Contants.js,如下所示 export default { Colors: { headerBackColor : '#7d1f7d', headerColor: '#EEFF41', } } 然后我在这样的组件中使用它 从“../../Constants”导入常量 const styles = StyleSheet.creat

我想在react原生应用程序中使用动态css样式。目前我使用的css样式来自一个文件,比如Contants.js,如下所示

export default {   
Colors: {      
    headerBackColor : '#7d1f7d',
    headerColor: '#EEFF41',           
   }    
}
然后我在这样的组件中使用它 从“../../Constants”导入常量

const styles = StyleSheet.create({ 
card: {
     backgroundColor: Constants.Colors.headerBackColor,
      }
});

我想从redux商店更改headerBackColor。我该怎么做????任何帮助都将不胜感激

我建议您只使用redux处理主题,并像以前那样存储颜色

减速器

let initialState = {theme: 'light'}

export default function themeManager(state = initialState, action){
    let nextState
    switch (action.type){
        case 'SET_THEME':
            if(action.theme)
            nextState = {
                ...state,
                theme: action.theme
            }
            return nextState
    default:
        return state
    }
}
组成部分

<Header style={this.props.theme === 'light' ? Constants.Colors.lightHeader : Constants.Colors.darkHeader}>...</Header>
const mapStateToProps = (state) => ({
    theme: state.theme
})

export default connect(mapStateToProps)(YourComponent)