screen-orientation
Track the screen orientation.
| Package | @vizejs/composable/screen-orientation |
| Own the source | vize lib pull composable:screen-orientation |
| Runtime exports | useScreenOrientation |
| Gzip budget | 1536 B |
Usage
import { useScreenOrientation } from "@vizejs/composable/screen-orientation";
Runtime contract
| Utility | Category | Stability | SSR | Hydration | Cleanup | Targets | Host globals | Uses |
|---|---|---|---|---|---|---|---|---|
useScreenOrientation |
system | experimental | deterministic-fallback | caller-managed | reactive-scope | web, desktop | window |
tryOnScopeDispose |
API
useScreenOrientation
Track the screen orientation. Server renders expose ssrOrientation with angle 0. The change listener follows the reactive host and is removed with the owning scope. Lock failures (not fullscreen, unsupported) resolve false instead of throwing. Inside a component the host is read after mounting, so hydration renders the server fallback first and never mismatches.
function useScreenOrientation( options: UseScreenOrientationOptions = {}, ): ScreenOrientationControls
Types
ScreenOrientationLike
Subset of ScreenOrientation, including the lock methods absent from some DOM typings.
| Member | Type | Description |
|---|---|---|
type |
OrientationType |
Current orientation type. |
angle |
number |
Current orientation angle in degrees. |
lock? |
(orientation: ScreenOrientationLockType) => Promise<void> |
Lock the orientation (fullscreen or installed apps only in most browsers). |
unlock? |
() => void |
Release an orientation lock. |
ScreenOrientationHost
Window-like capability observed by useScreenOrientation.
| Member | Type | Description |
|---|---|---|
screen |
{ readonly orientation?: ScreenOrientationLike } |
Screen exposing the orientation object. |
UseScreenOrientationOptions
Options for useScreenOrientation.
| Member | Type | Description |
|---|---|---|
ssrOrientation? |
OrientationType |
Orientation exposed during server rendering. |
host? |
MaybeRefOrGetter<ScreenOrientationHost | null | undefined> |
Reactive window capability for alternate runtimes and tests. |
ScreenOrientationControls
Reactive orientation state returned by useScreenOrientation.
| Member | Type | Description |
|---|---|---|
isSupported |
Readonly<Ref<boolean>> |
Whether the host exposes screen.orientation. false during server rendering. |
orientation |
Readonly<Ref<OrientationType>> |
Current orientation type. |
angle |
Readonly<Ref<number>> |
Current angle in degrees. |
lockOrientation |
(type: ScreenOrientationLockType) => Promise<boolean> |
Lock the orientation. |
unlockOrientation |
() => boolean |
Release a lock. |