@rnhooks/device-orientation
Version:
React Native hook for Device Orientation
39 lines (31 loc) • 1.05 kB
JavaScript
import { useState, useEffect } from 'react';
import { Dimensions } from 'react-native';
// eslint-disable-next-line no-unused-vars
var ORIENTATION = {
LANDSCAPE: 'landscape',
PORTRAIT: 'portrait'
};
function getWindowOrientation() {
var _Dimensions$get = Dimensions.get('window'),
width = _Dimensions$get.width,
height = _Dimensions$get.height;
return height >= width ? ORIENTATION.PORTRAIT : ORIENTATION.LANDSCAPE;
}
function useDeviceOrientation() {
var _useState = useState(getWindowOrientation),
deviceOrientation = _useState[0],
setDeviceOrientation = _useState[1];
useEffect(function () {
function updateState() {
setDeviceOrientation(getWindowOrientation());
}
Dimensions.addEventListener('change', updateState);
return function () {
return Dimensions.removeEventListener('change', updateState);
};
}, []);
return deviceOrientation;
}
export default useDeviceOrientation;
export { ORIENTATION };
//# sourceMappingURL=react-native-hooks-device-orientation.esm.js.map