I want to make file with variables of my colors and then import this file to my styles.
button: { color: primarycolor background: primarybackground }
So I can change colors only in one place.
To import color variables into styles with React Native, we can use export to export the color variables. export const COLORS = { white: '#fff', green: 'green', }; to create the color.
Choose Edit > Find and Replace Color… From there, select the color or Color Variable you want to find within your design and the color or Color Variable you want to replace it with. Enable “Include all opacities of this color” to find all colors with different alphas, but the same RGB or HEX values.
A color variable is a visual variable that defines the color of a symbol based on a numeric data value returned from a field or expression.
You can define a separate js file colors.js
, that consists of the colors object and export it.
export const COLORS = { white: '#fff', black: '#000', // your colors }
Now import COLORS from the above file - import {COLORS} from './<Path>/colors.js'
in your respective file that uses the defined colors. And use it as shown below.
button: { color: COLORS.white, backgroundColor: COLORS.black }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With