device-motion
Track device acceleration and rotation rate.
| Package | @vizejs/composable/device-motion |
| Own the source | vize lib pull composable:device-motion |
| Runtime exports | useDeviceMotion |
| Gzip budget | 2304 B |
Usage
import { useDeviceMotion } from "@vizejs/composable/device-motion";
Runtime contract
| Utility | Category | Stability | SSR | Hydration | Cleanup | Targets | Host globals | Uses |
|---|---|---|---|---|---|---|---|---|
useDeviceMotion |
sensors | experimental | deterministic-fallback | stable | reactive-scope | web, desktop | window |
requestMotionPermission, tryOnScopeDispose |
API
useDeviceMotion
Track device acceleration and rotation rate. Readings are copied into plain snapshots. Server renders expose null readings and isSupported: false; the listener is removed with the owning reactive scope. Shares the permission model of useDeviceOrientation.
function useDeviceMotion(options: UseDeviceMotionOptions = {}): DeviceMotionControls
Types
DeviceMotionHost
Window-like capability observed by useDeviceMotion.
| Member | Type | Description |
|---|---|---|
DeviceMotionEvent? |
MotionPermissionConstructor |
Constructor used to detect support and request permission. |
MotionVector
Acceleration along the device axes in m/s².
| Member | Type | Description |
|---|---|---|
x |
number | null |
X axis (left to right). |
y |
number | null |
Y axis (bottom to top). |
z |
number | null |
Z axis (back to front). |
MotionRotationRate
Rotation rate around the device axes in degrees per second.
| Member | Type | Description |
|---|---|---|
alpha |
number | null |
Around the Z axis. |
beta |
number | null |
Around the X axis. |
gamma |
number | null |
Around the Y axis. |
UseDeviceMotionOptions
Options for useDeviceMotion.
| Member | Type | Description |
|---|---|---|
host? |
MaybeRefOrGetter<DeviceMotionHost | null | undefined> |
Reactive window capability for alternate runtimes and tests. |
DeviceMotionControls
Reactive motion state returned by useDeviceMotion.
| Member | Type | Description |
|---|---|---|
isSupported |
Readonly<Ref<boolean>> |
Whether the host exposes DeviceMotionEvent. false during server rendering. |
acceleration |
Readonly<ShallowRef<MotionVector | null>> |
Acceleration without gravity; null before the first reading. |
accelerationIncludingGravity |
Readonly<ShallowRef<MotionVector | null>> |
Acceleration including gravity; null before the first reading. |
rotationRate |
Readonly<ShallowRef<MotionRotationRate | null>> |
Rotation rate; null before the first reading. |
interval |
Readonly<Ref<number>> |
Sampling interval in milliseconds. |
permission |
Readonly<Ref<MotionPermissionState>> |
Latest permission outcome; "granted" where no prompt exists. |
requestPermission |
() => Promise<MotionPermissionState> |
Request sensor permission where the platform requires it. |