source: imaps-frontend/node_modules/react-use/esm/useOrientation.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.3 KB
RevLine 
[d565449]1import { useEffect, useState } from 'react';
2import { off, on } from './misc/util';
3var defaultState = {
4 angle: 0,
5 type: 'landscape-primary',
6};
7var useOrientation = function (initialState) {
8 if (initialState === void 0) { initialState = defaultState; }
9 var _a = useState(initialState), state = _a[0], setState = _a[1];
10 useEffect(function () {
11 var screen = window.screen;
12 var mounted = true;
13 var onChange = function () {
14 if (mounted) {
15 var orientation_1 = screen.orientation;
16 if (orientation_1) {
17 var angle = orientation_1.angle, type = orientation_1.type;
18 setState({ angle: angle, type: type });
19 }
20 else if (window.orientation !== undefined) {
21 setState({
22 angle: typeof window.orientation === 'number' ? window.orientation : 0,
23 type: '',
24 });
25 }
26 else {
27 setState(initialState);
28 }
29 }
30 };
31 on(window, 'orientationchange', onChange);
32 onChange();
33 return function () {
34 mounted = false;
35 off(window, 'orientationchange', onChange);
36 };
37 }, []);
38 return state;
39};
40export default useOrientation;
Note: See TracBrowser for help on using the repository browser.