UNPKG

@applicaster/zapp-react-native-utils

Version:

Applicaster Zapp React Native utilities package

45 lines (37 loc) 1.32 kB
import * as R from "ramda"; import { isTV } from "@applicaster/zapp-react-native-utils/reactUtils"; import { useMemoizedIsTablet } from "@applicaster/zapp-react-native-utils/reactHooks/device"; import { useMobileOrientationEffect } from "./useMobileOrientationEffect"; import { noop } from "./utils"; type Props = { isTabletPortrait: boolean; docked: boolean; toggleFullscreen?: (params: { fullscreen: boolean }) => void; disable: boolean; skipInitialOrientationEffects: boolean; isRunningPlayNext: boolean; }; export const useOrientationEffect = ({ isTabletPortrait, docked, disable, toggleFullscreen = noop, isRunningPlayNext = false, skipInitialOrientationEffects = false, }: Props): void => { const isTablet = useMemoizedIsTablet(); const isTabletLandscape = !isTabletPortrait; const orientationShouldBeLandscape = isTablet && isTabletLandscape; // for mobile and tablet-portrait need to subscribe on orientation changes // for tablet-landscape or TV - no need to listen orientation changes const skipAllEffects = isTV() || R.isNil(isTablet) || disable || orientationShouldBeLandscape; useMobileOrientationEffect({ toggleFullscreen, docked, skipAllEffects, orientationShouldBeLandscape, skipInitialOrientationEffects, isRunningPlayNext, }); };