main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
1.4 KB
|
Line | |
---|
1 | "use strict";
|
---|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
3 | var react_1 = require("react");
|
---|
4 | var util_1 = require("./misc/util");
|
---|
5 | var defaultState = {
|
---|
6 | angle: 0,
|
---|
7 | type: 'landscape-primary',
|
---|
8 | };
|
---|
9 | var useOrientation = function (initialState) {
|
---|
10 | if (initialState === void 0) { initialState = defaultState; }
|
---|
11 | var _a = react_1.useState(initialState), state = _a[0], setState = _a[1];
|
---|
12 | react_1.useEffect(function () {
|
---|
13 | var screen = window.screen;
|
---|
14 | var mounted = true;
|
---|
15 | var onChange = function () {
|
---|
16 | if (mounted) {
|
---|
17 | var orientation_1 = screen.orientation;
|
---|
18 | if (orientation_1) {
|
---|
19 | var angle = orientation_1.angle, type = orientation_1.type;
|
---|
20 | setState({ angle: angle, type: type });
|
---|
21 | }
|
---|
22 | else if (window.orientation !== undefined) {
|
---|
23 | setState({
|
---|
24 | angle: typeof window.orientation === 'number' ? window.orientation : 0,
|
---|
25 | type: '',
|
---|
26 | });
|
---|
27 | }
|
---|
28 | else {
|
---|
29 | setState(initialState);
|
---|
30 | }
|
---|
31 | }
|
---|
32 | };
|
---|
33 | util_1.on(window, 'orientationchange', onChange);
|
---|
34 | onChange();
|
---|
35 | return function () {
|
---|
36 | mounted = false;
|
---|
37 | util_1.off(window, 'orientationchange', onChange);
|
---|
38 | };
|
---|
39 | }, []);
|
---|
40 | return state;
|
---|
41 | };
|
---|
42 | exports.default = useOrientation;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.