movie-web/src/components/player/hooks/useShouldShowControls.tsx

27 lines
996 B
TypeScript
Raw Normal View History

import { PlayerHoverState } from "@/stores/player/slices/interface";
import { usePlayerStore } from "@/stores/player/store";
2023-10-11 23:36:46 +02:00
export function useShouldShowControls() {
const hovering = usePlayerStore((s) => s.interface.hovering);
const lastHoveringState = usePlayerStore(
(s) => s.interface.lastHoveringState
);
const isPaused = usePlayerStore((s) => s.mediaPlaying.isPaused);
const hasOpenOverlay = usePlayerStore((s) => s.interface.hasOpenOverlay);
2023-10-11 23:36:46 +02:00
const isUsingTouch = lastHoveringState === PlayerHoverState.MOBILE_TAPPED;
const isHovering = hovering !== PlayerHoverState.NOT_HOVERING;
2023-10-11 23:36:46 +02:00
// when using touch, pause screens can be dismissed by tapping
const showTargetsWithoutPause = isHovering || hasOpenOverlay;
const showTargetsIncludingPause = showTargetsWithoutPause || isPaused;
const showTargets = isUsingTouch
? showTargetsWithoutPause
: showTargetsIncludingPause;
2023-10-11 23:36:46 +02:00
return {
showTouchTargets: isUsingTouch && showTargets,
showTargets,
};
}