UNPKG

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