Skip to content

Commit

Permalink
[Video] make hover state stick around if tapped (#5259)
Browse files Browse the repository at this point in the history
  • Loading branch information
mozzius authored Sep 11, 2024
1 parent c224921 commit fc25992
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 additions & 3 deletions src/view/com/util/post-embeds/VideoEmbedInner/VideoWebControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,39 @@ export function Controls({
}
}, [])

// these are used to trigger the hover state. on mobile, the hover state
// should stick around for a bit after they tap, and if the controls aren't
// present this initial tab should *only* show the controls and not activate anything

const onPointerDown = useCallback(
(evt: React.PointerEvent<HTMLDivElement>) => {
if (evt.pointerType !== 'mouse' && !hovered) {
evt.preventDefault()
}
},
[hovered],
)

const timeoutRef = useRef<ReturnType<typeof setTimeout>>()

const onHoverWithTimeout = useCallback(() => {
onHover()
clearTimeout(timeoutRef.current)
}, [onHover])

const onEndHoverWithTimeout = useCallback(
(evt: React.PointerEvent<HTMLDivElement>) => {
// if touch, end after 3s
// if mouse, end immediately
if (evt.pointerType !== 'mouse') {
setTimeout(onEndHover, 3000)
} else {
onEndHover()
}
},
[onEndHover],
)

const showControls =
((focused || autoplayDisabled) && !playing) ||
(interactingViaKeypress ? hasFocus : hovered)
Expand All @@ -261,9 +294,10 @@ export function Controls({
evt.stopPropagation()
setInteractingViaKeypress(false)
}}
onPointerEnter={onHover}
onPointerMove={onHover}
onPointerLeave={onEndHover}
onPointerEnter={onHoverWithTimeout}
onPointerMove={onHoverWithTimeout}
onPointerLeave={onEndHoverWithTimeout}
onPointerDown={onPointerDown}
onFocus={onFocus}
onBlur={onBlur}
onKeyDown={onKeyDown}>
Expand Down

0 comments on commit fc25992

Please sign in to comment.