Css 通过json数据响应本机动态主题
在react native中,如何在JSON数据中从服务器返回字体大小和背景颜色的动态样式上覆盖自定义样式?Css 通过json数据响应本机动态主题,css,ajax,reactjs,react-native,react-redux,Css,Ajax,Reactjs,React Native,React Redux,在react native中,如何在JSON数据中从服务器返回字体大小和背景颜色的动态样式上覆盖自定义样式? 我想在我的样式主题中设置JSON数据主题?你能给我发送接受JSON数据(如字体大小或颜色)并创建动态主题的那种样式的语法吗?你可以在组件中自定义你的样式,假设你有一个组件: const MyComponent = ({size, color}) => <Text style={{color: color, fontSize:size}}>Hello</Text&g
我想在我的样式主题中设置JSON数据主题?你能给我发送接受JSON数据(如字体大小或颜色)并创建动态主题的那种样式的语法吗?你可以在组件中自定义你的样式,假设你有一个组件:
const MyComponent = ({size, color}) => <Text style={{color: color, fontSize:size}}>Hello</Text>;
假设在您检索到的JSON数据中有color
和size
。
您可以随时将主题颜色和字体大小作为
<MyComponent color={themeJson.color} fontSize={themeJson.size} />
它将覆盖您在顶部定义的现有样式。希望这会有所帮助
<MyComponent color={themeJson.color} fontSize={themeJson.size} />
const styles= StyleSheet.create({
existStyle={
color: "red",
fontSize: 15
}
});
const MyComponent = ({size, color}) =>
<Text style={[styles.existStyle, {color: color, fontSize: size}] style={{color: color, fontSize:size}}>Hello</Text>;