1 | import { SyntheticPlatformEmitter } from '@unimodules/core';
|
2 | import { isSensorEnabledAsync, assertSensorEventEnabledAsync, } from './utils/isSensorEnabledAsync.web';
|
3 | const eventName = 'devicemotion';
|
4 | export default {
|
5 | get name() {
|
6 | return 'ExponentDeviceMotion';
|
7 | },
|
8 | |
9 |
|
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 |
|
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 |
|
\ | No newline at end of file |