telegram-tt/src/hooks/useHeavyAnimationCheckForVideo.ts
Alexander Zinchuk 3afcde3217 Initial commit
2021-04-09 14:11:51 +03:00

25 lines
705 B
TypeScript

import { RefObject } from 'react';
import { useCallback, useRef } from '../lib/teact/teact';
import useHeavyAnimationCheck from './useHeavyAnimationCheck';
import safePlay from '../util/safePlay';
export default function useHeavyAnimationCheckForVideo(playerRef: RefObject<HTMLVideoElement>, shouldPlay: boolean) {
const shouldPlayRef = useRef();
shouldPlayRef.current = shouldPlay;
const pause = useCallback(() => {
if (playerRef.current) {
playerRef.current.pause();
}
}, [playerRef]);
const play = useCallback(() => {
if (playerRef.current && shouldPlayRef.current) {
safePlay(playerRef.current);
}
}, [playerRef]);
useHeavyAnimationCheck(pause, play);
}