/
ExponentDeviceMotion.web.js
37 lines (37 loc) · 1.23 KB
/
ExponentDeviceMotion.web.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { SyntheticPlatformEmitter } from '@unimodules/core';
import { isSensorEnabledAsync } from './utils/isSensorEnabledAsync.web';
const eventName = 'devicemotion';
export default {
get name() {
return 'ExponentDeviceMotion';
},
/**
* Gravity on the planet this module supports (currently just Earth) represented as m/s^2.
*/
get Gravity() {
return 9.80665;
},
async isAvailableAsync() {
if (typeof DeviceMotionEvent === 'undefined') {
return false;
}
return await isSensorEnabledAsync(eventName);
},
_handleMotion(motion) {
// TODO: Bacon: Can rotation be calculated?
SyntheticPlatformEmitter.emit('deviceMotionDidUpdate', {
acceleration: motion.acceleration,
accelerationIncludingGravity: motion.accelerationIncludingGravity,
interval: motion.interval,
rotationRate: motion.rotationRate,
orientation: window.orientation,
});
},
startObserving() {
window.addEventListener(eventName, this._handleMotion);
},
stopObserving() {
window.removeEventListener(eventName, this._handleMotion);
},
};
//# sourceMappingURL=ExponentDeviceMotion.web.js.map