1 | import { SyntheticPlatformEmitter } from '@unimodules/core';
|
2 | import { isSensorEnabledAsync, assertSensorEventEnabledAsync, } from './utils/isSensorEnabledAsync.web';
|
3 | const scalar = Math.PI / 180;
|
4 | const eventName = 'deviceorientation';
|
5 | export default {
|
6 | get name() {
|
7 | return 'ExponentAccelerometer';
|
8 | },
|
9 | async isAvailableAsync() {
|
10 | if (typeof DeviceOrientationEvent === 'undefined') {
|
11 | return false;
|
12 | }
|
13 | return await isSensorEnabledAsync(eventName);
|
14 | },
|
15 | _handleMotion({ alpha, beta, gamma }) {
|
16 | SyntheticPlatformEmitter.emit('accelerometerDidUpdate', {
|
17 | x: gamma * scalar,
|
18 | y: beta * scalar,
|
19 | z: alpha * scalar,
|
20 | });
|
21 | },
|
22 | startObserving() {
|
23 | assertSensorEventEnabledAsync(eventName);
|
24 | window.addEventListener(eventName, this._handleMotion);
|
25 | },
|
26 | stopObserving() {
|
27 | window.removeEventListener(eventName, this._handleMotion);
|
28 | },
|
29 | };
|
30 |
|
\ | No newline at end of file |