UNPKG

@devloops/react-native-variant

Version:
2 lines 1.1 kB
import _slicedToArray from"@babel/runtime/helpers/slicedToArray";import{useEffect,useState}from'react';import{Dimensions}from'react-native';var screen=Dimensions.get('screen');export default function useDeviceOrientation(){var isOrientationPortrait=function isOrientationPortrait(_ref){var width=_ref.width,height=_ref.height;return height>=width;};var isOrientationLandscape=function isOrientationLandscape(_ref2){var width=_ref2.width,height=_ref2.height;return width>=height;};var _useState=useState({portrait:isOrientationPortrait(screen),landscape:isOrientationLandscape(screen)}),_useState2=_slicedToArray(_useState,2),orientation=_useState2[0],setOrientation=_useState2[1];var onChange=function onChange(_ref3){var screen=_ref3.screen;setOrientation({portrait:isOrientationPortrait(screen),landscape:isOrientationLandscape(screen)});};useEffect(function(){Dimensions.addEventListener('change',onChange);return function(){Dimensions.removeEventListener('change',onChange);};},[orientation.portrait,orientation.landscape]);return orientation;} //# sourceMappingURL=useDeviceOrientation.js.map