@doubao-apps/taro-runtime 0.0.28 → 0.0.29-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,10 @@
1
1
  import type Taro from '@tarojs/taro';
2
2
  type TaroStartDeviceMotionListeningOption = Taro.startDeviceMotionListening.Option;
3
3
  type TaroStopDeviceMotionListeningOption = Taro.stopDeviceMotionListening.Option;
4
+ type TaroDeviceMotionChangeCallback = Parameters<typeof Taro.onDeviceMotionChange>[0];
4
5
  export declare function startDeviceMotionListening(option: TaroStartDeviceMotionListeningOption): Promise<TaroGeneral.CallbackResult>;
5
6
  export declare function stopDeviceMotionListening(option?: TaroStopDeviceMotionListeningOption): Promise<TaroGeneral.CallbackResult>;
7
+ export declare function onDeviceMotionChange(callback: TaroDeviceMotionChangeCallback): void;
8
+ export declare function offDeviceMotionChange(callback?: TaroDeviceMotionChangeCallback): void;
6
9
  export {};
7
10
  //# sourceMappingURL=device-motion.d.ts.map
@@ -1,5 +1,6 @@
1
1
  import * as appFrameworkApi from '@byted-doubao-apps/framework/api';
2
2
  import { runCallbackApi } from '../utils.js';
3
+ const deviceMotionChangeCallbacks = new Map();
3
4
  export async function startDeviceMotionListening(option) {
4
5
  return runCallbackApi('startDeviceMotionListening', option, () => appFrameworkApi.startDeviceMotionListening({
5
6
  interval: option.interval
@@ -8,4 +9,33 @@ export async function startDeviceMotionListening(option) {
8
9
  export async function stopDeviceMotionListening(option) {
9
10
  return runCallbackApi('stopDeviceMotionListening', option, () => appFrameworkApi.stopDeviceMotionListening({}));
10
11
  }
12
+ export function onDeviceMotionChange(callback) {
13
+ if (typeof callback !== 'function' || deviceMotionChangeCallbacks.has(callback)) {
14
+ return;
15
+ }
16
+ const unregister = appFrameworkApi.onDeviceMotionChange((event) => {
17
+ callback({
18
+ alpha: event.alpha,
19
+ beta: event.beta,
20
+ gamma: event.gamma
21
+ });
22
+ });
23
+ deviceMotionChangeCallbacks.set(callback, unregister);
24
+ }
25
+ export function offDeviceMotionChange(callback) {
26
+ if (typeof callback === 'function') {
27
+ const unregister = deviceMotionChangeCallbacks.get(callback);
28
+ if (!unregister) {
29
+ return;
30
+ }
31
+ unregister();
32
+ deviceMotionChangeCallbacks.delete(callback);
33
+ return;
34
+ }
35
+ if (callback !== undefined) {
36
+ return;
37
+ }
38
+ deviceMotionChangeCallbacks.forEach((unregister) => unregister());
39
+ deviceMotionChangeCallbacks.clear();
40
+ }
11
41
  //# sourceMappingURL=device-motion.js.map
package/package.json CHANGED
@@ -37,7 +37,7 @@
37
37
  "access": "public",
38
38
  "registry": "https://registry.npmjs.org/"
39
39
  },
40
- "version": "0.0.28",
40
+ "version": "0.0.29-rc.0",
41
41
  "scripts": {
42
42
  "dev": "npm run build -- -w",
43
43
  "build": "rimraf dist bundle && tsc -p tsconfig.build.json",