Dimensions
Unistyles provides rich metadata about your device dimensions. This is useful for creating responsive designs as well as avoiding additional hooks that require passing values to stylesheets. Every prop can be accessed with UnistylesRuntime. Dimensions are always up to date and are updated based on Unistyles’ core logic, e.g., when the device orientation changes.
Accessing dimensions
In order to start using the dimensions metadata, you need to import UnistylesRuntime
:
UnistylesRuntime
can be used in your component as well as directly in the stylesheet.
Screen dimensions
The most basic dimensions are the screen dimensions. These are the dimensions of the screen that your app is running on.
You can access them with screen
prop:
Status bar
You can access status bar dimensions with statusBar
prop:
This prop may be useful for creating custom headers. In most of the cases status bar height is equal to the top inset, but on some devices it may be different.
Navigation bar
You can access navigation bar dimensions with navigationBar
prop:
This prop may be useful for creating custom bottom bars. In most of the cases navigation bar height is equal to the bottom inset, but on some devices it may be different.
Insets
Insets are the safe areas of the screen. They are used to avoid overlapping with system UI elements such as the status bar, navigation bar, and home indicator.
You can access them with insets
prop:
Insets can be used directly in your stylesheets to avoid passing values from useSafeAreaInsets
hook from react-native-safe-area-context library.
Insets on Android respect following setups:
Unistyles automatically reacts when you hide or show status and navigation bars. Yo can do that with UnistylesRuntime
as well.
Pixel ratio
Device Pixel Ratio (DPR) is the ratio between physical pixels and device-independent pixels (DIPs) on a screen. It determines how many physical pixels are used to represent a single CSS pixel.
Most likely your phone pixel ratio ranges between 1.0 to 3.0 (retina).
Font scale
Font scale is a ratio between the font size of the device and the default font size. It is used to adjust the size of text on the screen in companion with content size category.