From c25fac5b39d0a828c8c466ee8ea7bf50ab9a2f1d Mon Sep 17 00:00:00 2001 From: Samuel Newman <10959775+mozzius@users.noreply.github.com> Date: Thu, 1 Aug 2024 09:25:38 +0200 Subject: [PATCH] move around autoplay effects --- .../util/post-embeds/VideoWebControls.web.tsx | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/view/com/util/post-embeds/VideoWebControls.web.tsx b/src/view/com/util/post-embeds/VideoWebControls.web.tsx index bd4dfc328f..498ea94433 100644 --- a/src/view/com/util/post-embeds/VideoWebControls.web.tsx +++ b/src/view/com/util/post-embeds/VideoWebControls.web.tsx @@ -72,25 +72,25 @@ export function Controls({ } }, [interactingViaKeypress]) - const autoplayDisabled = useAutoplayDisabled() - - // autoplay + // pause + unfocus when another video is active useEffect(() => { - if (active && !autoplayDisabled) { - play() - } - return () => { + if (!active) { pause() setFocused(false) } - }, [active, play, pause, setFocused, autoplayDisabled]) + }, [active, pause, setFocused]) - // pause when offscreen + // autoplay/pause based on visibility + const autoplayDisabled = useAutoplayDisabled() useEffect(() => { - if (!onScreen) { - pause() + if (active && !autoplayDisabled) { + if (onScreen) { + play() + } else { + pause() + } } - }, [onScreen, pause]) + }, [onScreen, pause, active, play, autoplayDisabled]) const onPressPlayPause = useCallback(() => { if (!focused) {