fn
useScreenOrientation
v0.0.14testeddemoReactive Screen Orientation API. Tracks the current orientation
type and angle, and exposes helpers to lock/unlock the orientation. SSR-safe.
Examples
ts
const { isSupported, orientation, angle, lockOrientation, unlockOrientation } = useScreenOrientation();ts
// Lock to landscape (must run from a user gesture / fullscreen context)
const { lockOrientation } = useScreenOrientation();
await lockOrientation('landscape');Demo
Loading demo…
Signature
ts
export function useScreenOrientation(options: UseScreenOrientationOptions ={ ... }Parameters
| Parameter | Type | Description |
|---|---|---|
options? | UseScreenOrientationOptions | Options (custom window) |
Returns
UseScreenOrientationReturn{ isSupported, orientation, angle, lockOrientation, unlockOrientation }| Property | Type | Description |
|---|---|---|
isSupported | ComputedRef<boolean> | Whether the Screen Orientation API is supported |
orientation | ShallowRef<OrientationType | undefined> | Current screen orientation type, or undefined when unsupported |
angle | ShallowRef<number> | Current screen orientation angle in degrees (defaults to 0) |
lockOrientation | (type: OrientationLockType) => Promise<void> | Lock the screen to the given orientation. Rejects when unsupported. |
unlockOrientation | () => void | Release a previously applied orientation lock. No-op when unsupported. |