Skip to main content

Orientation Utilities

This document provides an overview of the orientation-related utility functions available in the react-native-video-toolkit.

shouldRotate

Determines if the screen should rotate to landscape based on the provided dimensions and configuration.

Usage

import { shouldRotate } from 'react-native-video-toolkit';

const canRotate = shouldRotate(1920, 1080);

Parameters

ParameterTypeRequiredDefaultDescription
widthnumberYesThe width of the screen.
heightnumberYesThe height of the screen.
configRotationConfigNo{}Configuration options for rotation detection.

Returns

TypeDescription
booleantrue if the screen should rotate, false otherwise.

Example

import { shouldRotate } from 'react-native-video-toolkit';

const config = {
threshold: 1.5,
minWidth: 768,
};

const canRotate = shouldRotate(1920, 1080, config);

detectDeviceType

Detects the type of the device based on the screen dimensions.

Usage

import { detectDeviceType } from 'react-native-video-toolkit';

const deviceType = detectDeviceType();

Returns

TypeDescription
DeviceTypeThe type of the device ('phone', 'tablet', 'foldable', 'tv', 'desktop', or 'unknown').

Example

import { detectDeviceType } from 'react-native-video-toolkit';

const deviceType = detectDeviceType();
// deviceType will be 'phone', 'tablet', etc.

getOptimalConfig

Returns the optimal rotation configuration for the current platform and device.

Usage

import { getOptimalConfig } from 'react-native-video-toolkit';

const config = getOptimalConfig();

Returns

TypeDescription
RotationConfigThe optimal rotation configuration for the current device.

Example

import { getOptimalConfig } from 'react-native-video-toolkit';

const config = getOptimalConfig();
// config will be { threshold: 1.5, minWidth: 768 }

useShouldRotate

A hook that returns a boolean indicating whether the screen should rotate to landscape.

Usage

import { useShouldRotate } from 'react-native-video-toolkit';

const shouldRotate = useShouldRotate();

Returns

TypeDescription
booleantrue if the screen should rotate, false otherwise.

Example

import { useShouldRotate } from 'react-native-video-toolkit';
import { Text } from 'react-native';

const MyComponent = () => {
const shouldRotate = useShouldRotate();
return <Text>{shouldRotate ? 'Rotate' : 'Do not rotate'}</Text>;
};

getVideoControlsConfig

Returns the configuration for the video controls based on the screen orientation and platform.

Usage

import { getVideoControlsConfig } from 'react-native-video-toolkit';

const config = getVideoControlsConfig(true, 'web');

Parameters

ParameterTypeRequiredDefaultDescription
isLandscapebooleanYesWhether the screen is in landscape mode.
platformstringYesThe current platform ('web', 'mobile', or 'tv').

Returns

TypeDescription
objectThe configuration for the video controls.

Example

import { getVideoControlsConfig } from 'react-native-video-toolkit';

const config = getVideoControlsConfig(true, 'web');
// config will be { showFullscreen: false, showSeekBar: true, ... }

PlatformUtils

An object containing utility functions for platform detection.

Usage

import { PlatformUtils } from 'react-native-video-toolkit';

const isWeb = PlatformUtils.isWeb();

Properties

PropertyTypeDescription
isTV() => booleanReturns true if the platform is a TV.
isWeb() => booleanReturns true if the platform is the web.
isMobile() => booleanReturns true if the platform is mobile.
isTVOS() => booleanReturns true if the platform is tvOS.
isAndroidTV() => booleanReturns true if the platform is Android TV.
isBrowser() => booleanReturns true if the code is running in a browser.
isDesktop() => booleanReturns true if the device is a desktop.
isTablet() => booleanReturns true if the device is a tablet.

Example

import { PlatformUtils } from 'react-native-video-toolkit';

const isWeb = PlatformUtils.isWeb();
// isWeb will be true if the platform is web