diff options
author | Samuel Newman <mozzius@protonmail.com> | 2024-09-11 04:19:37 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-10 20:19:37 -0700 |
commit | fc25992070633af9c242712fe6234a518200ef9b (patch) | |
tree | 16d9da5be92fe25d62d92fe145c4f66671b10fcb /src/view/com/util/post-embeds/VideoEmbedInner/VideoWebControls.tsx | |
parent | c22492147b8b5904ceb205b87d0852ffcf4c8d24 (diff) | |
download | voidsky-fc25992070633af9c242712fe6234a518200ef9b.tar.zst |
[Video] make hover state stick around if tapped (#5259)
Diffstat (limited to 'src/view/com/util/post-embeds/VideoEmbedInner/VideoWebControls.tsx')
-rw-r--r-- | src/view/com/util/post-embeds/VideoEmbedInner/VideoWebControls.tsx | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/src/view/com/util/post-embeds/VideoEmbedInner/VideoWebControls.tsx b/src/view/com/util/post-embeds/VideoEmbedInner/VideoWebControls.tsx index e9005a37e..590dc0c27 100644 --- a/src/view/com/util/post-embeds/VideoEmbedInner/VideoWebControls.tsx +++ b/src/view/com/util/post-embeds/VideoEmbedInner/VideoWebControls.tsx @@ -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) @@ -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}> |