Themes
As Nativewind uses Tailwind CLI, it supports all the theming options Tailwind CSS does. Read the Tailwind CSS docs on each className to learn more about the possible theming values.
Dynamic themes
To transition from a static theme to a dynamic one in Nativewind, utilize CSS Variables as colors. This approach ensures flexibility and adaptability in theme application, catering to user preferences.
Switching themes
Nativewind is unopinionated on how you implement your theming. This is an example implementation that supports two themes with both a light/dark mode.
Retrieving theme values
Accessing default colors
If you need the default color values at runtime, you can import them directly from tailwindcss
retrieve them directly from tailwindcss/colors
Access theme values
If you use custom theme values, extract them to a file that is shared with your code and your tailwind.config.js
. Please read the Tailwind CSS documentation for more information.
Platform specific theming
platformSelect
platformSelect is the equivalent to Platform.select()
platformColor()
Equivalent of PlatformColor
. Typically used with platformSelect
.
Device specific theming
hairlineWidth()
Equivalent of StyleSheet.hairlineWidth
pixelRatio()
Equivalent of PixelRatio.get()
. If a number is provided it returns PixelRatio.get() * <value>
, otherwise it returns the PixelRatio value.
pixelRatioSelect()
A helper function to use PixelRatio.get()
in a conditional statement, similar to Platform.select
.
fontScale()
Equivalent of PixelRatio.getFontScale()
. If a number is provided it returns PixelRatio.getFontScale() * <value>
, otherwise it returns the PixelRatio.getFontScale()
value.
fontScaleSelect()
A helper function to use PixelRatio.getFontScale()
in a conditional statement, similar to Platform.select
.
getPixelSizeForLayoutSize()
Equivalent of PixelRatio.getPixelSizeForLayoutSize()
roundToNearestPixel()
Equivalent of PixelRatio.roundToNearestPixel()