Skip to main content

@rtorcato/browser-common / orientation

orientation

Type Aliases​

OrientationLockType​

OrientationLockType = "any" | "natural" | "landscape" | "portrait" | "portrait-primary" | "portrait-secondary" | "landscape-primary" | "landscape-secondary"

Defined in: orientation/index.ts:51

Orientation values accepted by screen.orientation.lock(). Declared locally because OrientationLockType is missing from some TypeScript lib.dom versions.

Functions​

isDeviceOrientationAvailable()​

isDeviceOrientationAvailable(): boolean

Defined in: orientation/index.ts:10

Checks if the DeviceOrientation API is available in the browser.

Example​

import { isDeviceOrientationAvailable } from '@rtorcato/browser-common/orientation'
if (isDeviceOrientationAvailable()) listen()

Returns​

boolean

True if DeviceOrientationEvent is supported, false otherwise.


onDeviceOrientation()​

onDeviceOrientation(callback): () => void

Defined in: orientation/index.ts:25

Adds a listener for device orientation changes.

Example​

import { onDeviceOrientation } from '@rtorcato/browser-common/orientation'
const off = onDeviceOrientation((e) => console.log(e.alpha, e.beta, e.gamma))
off()

Parameters​

callback​

(event) => void

The callback to run on orientation change.

Returns​

A function to remove the event listener.

() => void


getScreenOrientationType()​

getScreenOrientationType(): string | undefined

Defined in: orientation/index.ts:40

Gets the current screen orientation type (e.g., 'portrait-primary', 'landscape-primary').

Example​

import { getScreenOrientationType } from '@rtorcato/browser-common/orientation'
const type = getScreenOrientationType()

Returns​

string | undefined

The orientation type, or undefined if not available.


lockScreenOrientation()​

lockScreenOrientation(type): Promise<void> | undefined

Defined in: orientation/index.ts:74

Locks the screen orientation to a specific type (if supported).

Example​

import { lockScreenOrientation } from '@rtorcato/browser-common/orientation'
await lockScreenOrientation('landscape-primary')

Parameters​

type​

OrientationLockType

The orientation type (e.g., 'portrait-primary', 'landscape-primary').

Returns​

Promise<void> | undefined

A promise that resolves when locked, or undefined if not supported.


unlockScreenOrientation()​

unlockScreenOrientation(): void

Defined in: orientation/index.ts:91

Unlocks the screen orientation (if supported).

Example​

import { unlockScreenOrientation } from '@rtorcato/browser-common/orientation'
unlockScreenOrientation()

Returns​

void