From 991202966e79e85667474f2e6a6d330f8112f70a Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Wed, 11 Sep 2024 19:36:54 +0100 Subject: [PATCH] [Video] Fix web autoplay (#5274) --- .../com/util/post-embeds/VideoEmbed.web.tsx | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/view/com/util/post-embeds/VideoEmbed.web.tsx b/src/view/com/util/post-embeds/VideoEmbed.web.tsx index a41bf263..908c06e2 100644 --- a/src/view/com/util/post-embeds/VideoEmbed.web.tsx +++ b/src/view/com/util/post-embeds/VideoEmbed.web.tsx @@ -43,16 +43,6 @@ export function VideoEmbed({embed}: {embed: AppBskyEmbedVideo.View}) { return () => observer.disconnect() }, [sendPosition, isFullscreen]) - // In case scrolling hasn't started yet, send up the position - const isAnyViewActive = currentActiveView !== null - useEffect(() => { - if (ref.current && !isAnyViewActive) { - const rect = ref.current.getBoundingClientRect() - const position = rect.y + rect.height / 2 - sendPosition(position) - } - }, [isAnyViewActive, sendPosition]) - const [key, setKey] = useState(0) const renderError = useCallback( (error: unknown) => ( @@ -84,7 +74,9 @@ export function VideoEmbed({embed}: {embed: AppBskyEmbedVideo.View}) { style={{display: 'flex', flex: 1, cursor: 'default'}} onClick={evt => evt.stopPropagation()}> - + void + isAnyViewActive: boolean }) { const ref = useRef(null) const [nearScreen, setNearScreen] = useState(false) @@ -134,6 +128,15 @@ function ViewportObserver({ return () => observer.disconnect() }, [sendPosition, isFullscreen]) + // In case scrolling hasn't started yet, send up the position + useEffect(() => { + if (ref.current && !isAnyViewActive) { + const rect = ref.current.getBoundingClientRect() + const position = rect.y + rect.height / 2 + sendPosition(position) + } + }, [isAnyViewActive, sendPosition]) + return ( {nearScreen && children}