source: imaps-frontend/node_modules/react-use/lib/useMotion.js

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.7 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var react_1 = require("react");
4var util_1 = require("./misc/util");
5var defaultState = {
6 acceleration: {
7 x: null,
8 y: null,
9 z: null,
10 },
11 accelerationIncludingGravity: {
12 x: null,
13 y: null,
14 z: null,
15 },
16 rotationRate: {
17 alpha: null,
18 beta: null,
19 gamma: null,
20 },
21 interval: 16,
22};
23var useMotion = function (initialState) {
24 if (initialState === void 0) { initialState = defaultState; }
25 var _a = react_1.useState(initialState), state = _a[0], setState = _a[1];
26 react_1.useEffect(function () {
27 var handler = function (event) {
28 var acceleration = event.acceleration, accelerationIncludingGravity = event.accelerationIncludingGravity, rotationRate = event.rotationRate, interval = event.interval;
29 setState({
30 acceleration: {
31 x: acceleration.x,
32 y: acceleration.y,
33 z: acceleration.z,
34 },
35 accelerationIncludingGravity: {
36 x: accelerationIncludingGravity.x,
37 y: accelerationIncludingGravity.y,
38 z: accelerationIncludingGravity.z,
39 },
40 rotationRate: {
41 alpha: rotationRate.alpha,
42 beta: rotationRate.beta,
43 gamma: rotationRate.gamma,
44 },
45 interval: interval,
46 });
47 };
48 util_1.on(window, 'devicemotion', handler);
49 return function () {
50 util_1.off(window, 'devicemotion', handler);
51 };
52 }, []);
53 return state;
54};
55exports.default = useMotion;
Note: See TracBrowser for help on using the repository browser.