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. Status bar height is not dynamic and won’t cover hiding it.
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. Navigation bar height is not dynamic.
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: