UNPKG

@rnhooks/device-orientation

Version:
43 lines (33 loc) 1.18 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var react = require('react'); var reactNative = require('react-native'); // eslint-disable-next-line no-unused-vars var ORIENTATION = { LANDSCAPE: 'landscape', PORTRAIT: 'portrait' }; function getWindowOrientation() { var _Dimensions$get = reactNative.Dimensions.get('window'), width = _Dimensions$get.width, height = _Dimensions$get.height; return height >= width ? ORIENTATION.PORTRAIT : ORIENTATION.LANDSCAPE; } function useDeviceOrientation() { var _useState = react.useState(getWindowOrientation), deviceOrientation = _useState[0], setDeviceOrientation = _useState[1]; react.useEffect(function () { function updateState() { setDeviceOrientation(getWindowOrientation()); } reactNative.Dimensions.addEventListener('change', updateState); return function () { return reactNative.Dimensions.removeEventListener('change', updateState); }; }, []); return deviceOrientation; } exports.ORIENTATION = ORIENTATION; exports.default = useDeviceOrientation; //# sourceMappingURL=react-native-hooks-device-orientation.cjs.js.map