У React Native є можливість працювати з кольорами. Синтаксис подібний до CSS. Тільки слід пам'ятати, що під час стилізації всі значення потрібно задавати в лапках. Розглянемо способи задання кольору нижче на прикладі стилізації контейнера (його заливки backgroundColor).
Copy const styles = StyleSheet.create({
container: {
backgroundColor: "#f0f", // #rgb
backgroundColor: "#ff00ff", // #rrggbb
backgroundColor: "#f0ff", // #rgba
backgroundColor: "#ff00ff00", // #rrggbbaa
backgroundColor: "rgb(255, 0, 255)",
backgroundColor: "rgb(255 0 255)",
backgroundColor: "rgba(255, 0, 255, 1.0)",
backgroundColor: "rgba(255 0 255 / 1.0)",
},
});
Copy const styles = StyleSheet.create({
container: {
backgroundColor: "hsl(360, 100%, 100%)",
backgroundColor: "hsl(360 100% 100%)",
backgroundColor: "hsla(360, 100%, 100%, 1.0)",
backgroundColor: "hsla(360 100% 100% / 1.0)",
},
});
Copy const styles = StyleSheet.create({
container: {
backgroundColor: "hwb(0, 0%, 100%)",
backgroundColor: "hwb(360, 100%, 100%)",
backgroundColor: "hwb(0 0% 0%)",
backgroundColor: "hwb(70 50% 0%)",
},
});
Copy const styles = StyleSheet.create({
container: {
backgroundColor: 0xff00ffff, //0xrrggbbaa
},
});
Copy const styles = StyleSheet.create({
container: {
backgroundColor: "black", // #000000
backgroundColor: "blue", // #0000ff
backgroundColor: "gold", // #ffd700
backgroundColor: "green", // #008000
backgroundColor: "yellow", // #ffff00
backgroundColor: "gray", // #808080
backgroundColor: "grey", // #808080
},
});