Implement custom dynamic themes using json data

In the native answer, how can I redefine my user style with a dynamic style in which the font color and background color are returned from the server in JSON data? And I want to install a JSON data theme in my style themes? Can you send me the syntax of this type of style that accepts JSON data, such as font size or color, and creates a dynamic theme?

+4
source share
1 answer

you can always customize your style in the component, suppose you have a component:

const MyComponent = ({size, color}) => <Text style={{color: color, fontSize:size}}>Hello</Text>;

in your parent component, you can get your topic data from the side, for example

const themeJson = retrieveTheme()  // some API call

, color size ur, JSON. MyComponent

<MyComponent color={themeJson.color} fontSize={themeJson.size} />

JSON .

native , StyleSheet , , , React ( JSON), ,

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>;

, . , .

0

Source: https://habr.com/ru/post/1675767/


All Articles