UNPKG

@rnhooks/device-orientation

Version:
46 lines (36 loc) 1.6 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('react-native')) : typeof define === 'function' && define.amd ? define(['exports', 'react', 'react-native'], factory) : (global = global || self, factory(global['react-native-hooks-device-orientation'] = {}, global.React, global.reactNative)); }(this, function (exports, react, reactNative) { 'use strict'; // 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; Object.defineProperty(exports, '__esModule', { value: true }); })); //# sourceMappingURL=react-native-hooks-device-orientation.js.map