@capacitor/motion 8.0.0 → 8.0.1-dev-2558-20260630T112728.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.
Files changed (2) hide show
  1. package/README.md +28 -3
  2. package/package.json +2 -3
package/README.md CHANGED
@@ -12,7 +12,7 @@ npx cap sync
12
12
  ## Permissions
13
13
 
14
14
  This plugin is currently implemented using Web APIs. Most browsers require
15
- permission before using this API. To request permission, prompt the user for
15
+ permission before using these APIs. To request permission, prompt the user for
16
16
  permission on any user-initiated action (such as a button click):
17
17
 
18
18
  ```typescript
@@ -21,8 +21,9 @@ import { Motion } from '@capacitor/motion';
21
21
 
22
22
 
23
23
  let accelHandler: PluginListenerHandle;
24
+ let orientationHandler: PluginListenerHandle;
24
25
 
25
- myButton.addEventListener('click', async () => {
26
+ myAccelerationButton.addEventListener('click', async () => {
26
27
  try {
27
28
  await DeviceMotionEvent.requestPermission();
28
29
  } catch (e) {
@@ -36,6 +37,20 @@ myButton.addEventListener('click', async () => {
36
37
  });
37
38
  });
38
39
 
40
+ myOrientationButton.addEventListener('click', async () => {
41
+ try {
42
+ await DeviceOrientationEvent.requestPermission();
43
+ } catch (e) {
44
+ // Handle error
45
+ return;
46
+ }
47
+
48
+ // Once the user approves, can start listening:
49
+ orientationHandler = await Motion.addListener('orientation', event => {
50
+ console.log('Device orientation event:', event);
51
+ });
52
+ });
53
+
39
54
  // Stop the acceleration listener
40
55
  const stopAcceleration = () => {
41
56
  if (accelHandler) {
@@ -43,6 +58,13 @@ const stopAcceleration = () => {
43
58
  }
44
59
  };
45
60
 
61
+ // Stop the orientation listener
62
+ const stopOrientation = () => {
63
+ if (orientationHandler) {
64
+ orientationHandler.remove();
65
+ }
66
+ };
67
+
46
68
  // Remove all listeners
47
69
  const removeListeners = () => {
48
70
  Motion.removeAllListeners();
@@ -51,7 +73,10 @@ const removeListeners = () => {
51
73
 
52
74
  See the
53
75
  [`DeviceMotionEvent`](https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent)
54
- API to understand the data supplied in the 'accel' event.
76
+ and
77
+ [`DeviceOrientationEvent`](https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent)
78
+ APIs to understand the data supplied in the `'accel'` and `'orientation'`
79
+ events respectively.
55
80
 
56
81
  ## API
57
82
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capacitor/motion",
3
- "version": "8.0.0",
3
+ "version": "8.0.1-dev-2558-20260630T112728.0",
4
4
  "description": "The Motion API tracks accelerometer and device orientation (compass heading, etc.)",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
@@ -62,6 +62,5 @@
62
62
  "capacitor": {},
63
63
  "publishConfig": {
64
64
  "access": "public"
65
- },
66
- "gitHead": "c1fe5621b3b2ba57585b94d2a71491aa8bcac7eb"
65
+ }
67
66
  }