UNPKG

1.03 kBJavaScriptView Raw
1import { SyntheticPlatformEmitter } from '@unimodules/core';
2import { isSensorEnabledAsync, assertSensorEventEnabledAsync, } from './utils/isSensorEnabledAsync.web';
3const eventName = 'devicemotion';
4export default {
5 get name() {
6 return 'ExponentGyroscope';
7 },
8 async isAvailableAsync() {
9 if (typeof DeviceMotionEvent === 'undefined') {
10 return false;
11 }
12 return await isSensorEnabledAsync(eventName);
13 },
14 _handleMotion({ accelerationIncludingGravity }) {
15 SyntheticPlatformEmitter.emit('gyroscopeDidUpdate', {
16 x: accelerationIncludingGravity.x,
17 y: accelerationIncludingGravity.y,
18 z: accelerationIncludingGravity.z,
19 });
20 },
21 startObserving() {
22 assertSensorEventEnabledAsync(eventName);
23 window.addEventListener(eventName, this._handleMotion);
24 },
25 stopObserving() {
26 window.removeEventListener(eventName, this._handleMotion);
27 },
28};
29//# sourceMappingURL=ExponentGyroscope.web.js.map
\No newline at end of file