fn

useDeviceOrientation

v0.0.14testeddemo

Reactive DeviceOrientationEvent. Provides physical orientation of the device relative to Earth's coordinate frame. SSR-safe, uses a single passive listener, and supports the iOS 13+ permission flow.

Examples

ts
const { isSupported, isAbsolute, alpha, beta, gamma } = useDeviceOrientation();
ts
// iOS 13+: request permission from a user gesture
const { ensurePermissions, alpha, beta, gamma } = useDeviceOrientation();
button.addEventListener('click', ensurePermissions);

Demo

Loading demo…

Signature

ts
export function useDeviceOrientation(options: UseDeviceOrientationOptions ={ ... }

Parameters

ParameterTypeDescription
options?UseDeviceOrientationOptionsOptions

Returns

UseDeviceOrientationReturnisSupported, isAbsolute, the alpha/beta/gamma angles, and the permission state
PropertyTypeDescription
isSupportedComputedRef<boolean>Whether the DeviceOrientationEvent is supported in the current environment.
requirePermissionsComputedRef<boolean>Whether an explicit permission grant is required (iOS 13+).
permissionGrantedShallowRef<boolean>Whether orientation permission has been granted.
isAbsoluteShallowRef<boolean>Whether the device is providing orientation data absolutely (relative to Earth's coordinate frame) rather than relative to an arbitrary frame.
alphaShallowRef<number | null>Motion of the device around the z axis, in degrees (0–360), or null when unavailable.
betaShallowRef<number | null>Motion of the device around the x axis, in degrees (-180–180), or null when unavailable.
gammaShallowRef<number | null>Motion of the device around the y axis, in degrees (-90–90), or null when unavailable.
ensurePermissions() => Promise<void>Request orientation permission (iOS 13+). Must be triggered by a user gesture. Resolves once the request settles; on grant the listener is attached.