From 6eabedd037e6631eef4be5302b25e6cdba18f126 Mon Sep 17 00:00:00 2001 From: Hailey Date: Thu, 5 Sep 2024 14:54:09 -0700 Subject: [Video] More adjustments for loading state jank (#5171) --- src/view/com/util/post-embeds/VideoEmbed.tsx | 90 +++++++++++++++------------- 1 file changed, 47 insertions(+), 43 deletions(-) (limited to 'src') diff --git a/src/view/com/util/post-embeds/VideoEmbed.tsx b/src/view/com/util/post-embeds/VideoEmbed.tsx index 2dafce7ba..7db25b4d0 100644 --- a/src/view/com/util/post-embeds/VideoEmbed.tsx +++ b/src/view/com/util/post-embeds/VideoEmbed.tsx @@ -68,7 +68,9 @@ function InnerWrapper({embed}: Props) { useActiveVideoNative() const viewId = useId() - const [playerStatus, setPlayerStatus] = useState('loading') + const [playerStatus, setPlayerStatus] = useState< + VideoPlayerStatus | 'switching' + >('loading') const [isMuted, setIsMuted] = useState(player.muted) const [isFullscreen, setIsFullscreen] = React.useState(false) const [timeRemaining, setTimeRemaining] = React.useState(0) @@ -77,6 +79,8 @@ function InnerWrapper({embed}: Props) { isActive && (playerStatus === 'waitingToPlayAtSpecifiedRate' || playerStatus === 'loading') + const isSwitching = playerStatus === 'switching' + const showOverlay = !isActive || isLoading || isSwitching // send error up to error boundary const [error, setError] = useState(null) @@ -130,6 +134,7 @@ function InnerWrapper({embed}: Props) { player.play() } } else { + setPlayerStatus('switching') player.muted = true if (player.playing) { player.pause() @@ -148,48 +153,47 @@ function InnerWrapper({embed}: Props) { setIsFullscreen={setIsFullscreen} /> ) : null} - {!isActive || isLoading ? ( - - {embed.alt} - - - ) : null} + + {embed.alt} + + ) } -- cgit 1.4.1