简体   繁体   中英

React-Native: get theme variables from backend

I have a file, for example theme.js and inside my theme.js i use constants for my theming.

const config = {
 BACKGROUND: 'white'
 ..//
}
export default config;

my usage example:

<View style={{ backgroundColor: theme.BACKGROUND }} />

Now i may receive some properties from the server, for example button color or something like that. And I want to override the properties in my js file. Curently whenever I use theme. I use it directly by importing the file. The problem is once it is imported. We can't change the values. It would be really helpful if someone can tell me how can i receive theme variables efficiently from internet and load them accordingly.

Not a very good solution but a work around would be this :

You can fetch theme variables in your app.js and save it in redux store or you can save response in asyncStorage

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM