Skip to main content

@rtorcato/browser-common / orientation

orientation

Functions

isDeviceOrientationAvailable()

isDeviceOrientationAvailable(): boolean

Defined in: orientation/index.ts:10

Checks if the DeviceOrientation API is available in the browser.

Returns

boolean

True if DeviceOrientationEvent is supported, false otherwise.

Example

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

onDeviceOrientation()

onDeviceOrientation(callback): () => void

Defined in: orientation/index.ts:25

Adds a listener for device orientation changes.

Parameters

callback

(event) => void

The callback to run on orientation change.

Returns

A function to remove the event listener.

() => void

Example

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

getScreenOrientationType()

getScreenOrientationType(): string | undefined

Defined in: orientation/index.ts:40

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

Returns

string | undefined

The orientation type, or undefined if not available.

Example

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

lockScreenOrientation()

lockScreenOrientation(type): Promise<void> | undefined

Defined in: orientation/index.ts:57

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

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.

Example

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

unlockScreenOrientation()

unlockScreenOrientation(): void

Defined in: orientation/index.ts:78

Unlocks the screen orientation (if supported).

Returns

void

Example

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