React Native API 🎣 that adds event listener(s) for the Dimsnsions
change
event. Also, this will return the initial Dimensions when called.
React Native has two dimensions, screen
and window
. On iOS these are the same, but on Android the values returned are different. From the docs:
For Android the
window
dimension will exclude the size used by thestatus bar
(if not translucent) andbottom navigation bar
Any number of types can be requested, but defaults are set per Platform.
Type | Defaults |
---|---|
SCREEN | Android |
WINDOW | Android, iOS |
import {useDimensions, types} from 'react-native-use'
const {DimensionsTypes} = types;
const {window: {height, width}} = useDimensions(DimensionsTypes.WINDOW);