Appearance
useScreenOrientation
Reactive Screen Orientation API
Demo
Usage
tsx
import { useScreenOrientation } from '@reause/core'
const {
isSupported,
orientation,
angle,
lockOrientation,
unlockOrientation,
} = useScreenOrientation()To lock the orientation, you can pass an OrientationLockType to the lockOrientation function:
tsx
lockOrientation('portrait-primary')and then unlock again, with the following:
tsx
unlockOrientation()Accepted orientation types are one of "landscape-primary", "landscape-secondary", "portrait-primary", "portrait-secondary", "any", "landscape", "natural" and "portrait".
Type Declarations
Toggle
ts
export type OrientationType = 'portrait-primary' | 'portrait-secondary' | 'landscape-primary' | 'landscape-secondary'
export type OrientationLockType = 'any' | 'natural' | 'landscape' | 'portrait' | 'portrait-primary' | 'portrait-secondary' | 'landscape-primary' | 'landscape-secondary'
export interface ScreenOrientation extends EventTarget {
lock: (orientation: OrientationLockType) => Promise<void>;
unlock: () => void;
readonly type: OrientationType;
readonly angle: number;
addEventListener: (type: 'change', listener: (this: this, ev: Event) => any, useCapture?: boolean) => void;
}
export interface UseScreenOrientationOptions {
window?: Window;
}
export interface UseScreenOrientationReturn {
isSupported: boolean;
orientation: OrientationType | undefined;
angle: number;
lockOrientation: (type: OrientationLockType) => Promise<void>;
unlockOrientation: () => void;
}
export function useScreenOrientation(options?: UseScreenOrientationOptions): UseScreenOrientationReturn