StyleSheet
StyleSheet
replaces the old createStyleSheet
function and aims for 1:1 parity with the React Native API.
When we say that Unistyles is a superset of StyleSheet, we mean it! That’s why we are taking it one step further!
create
The create
function supports all styles that React Native’s StyleSheet does, and it also enables some superpowers 🦸🏼♂️.
It can parse your variants
, compoundVariants
or dynamic functions
(even if you haven’t configured Unistyles yet!).
Once you register your themes
and breakpoints
, it unlocks even more features, like injecting the current theme
or miniRuntime
into your stylesheet.
It also assists you with TypeScript autocompletion for your styles.
Example usage:
Will be eg. parsed to:
Unistyles StyleSheet will automatically react and re-calculate your styles if any of your dependencies change. Learn more about it here.
StyleSheet.create
supports 3 ways of defining your stylesheets:
Static StyleSheet
Themable StyleSheet
Themable StyleSheet with miniRuntime
Learn more about miniRuntime
here.
configure
StyleSheet.configure
is used to configure Unistyles. It accepts an object with the following properties:
themes
your apps themesbreakpoints
your apps breakpointssettings
additional settings
This config is scoped across the whole app, unless your limit it with a scoped themes.
The configure
function should be called before you import any component that uses Unistyles StyleSheet.
You can learn more about how to configure Unistyles here.
hairlineWidth
StyleSheet.hairlineWidth
is a static value representing the smallest value that can be drawn on your device. It’s helpful for borders or dividers.
compose
Maps to React Native’s compose function.
flatten
Maps to React Native’s flatten function.
absoluteFillObject
Returns following object:
absoluteFill
Returns following object: