Skip to content

Commit 6eabedd

Browse files
authored
[Video] More adjustments for loading state jank (#5171)
1 parent 7eb4cd8 commit 6eabedd

File tree

2 files changed

+48
-44
lines changed

2 files changed

+48
-44
lines changed

src/view/com/util/post-embeds/VideoEmbed.tsx

Lines changed: 47 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ function InnerWrapper({embed}: Props) {
6868
useActiveVideoNative()
6969
const viewId = useId()
7070

71-
const [playerStatus, setPlayerStatus] = useState<VideoPlayerStatus>('loading')
71+
const [playerStatus, setPlayerStatus] = useState<
72+
VideoPlayerStatus | 'switching'
73+
>('loading')
7274
const [isMuted, setIsMuted] = useState(player.muted)
7375
const [isFullscreen, setIsFullscreen] = React.useState(false)
7476
const [timeRemaining, setTimeRemaining] = React.useState(0)
@@ -77,6 +79,8 @@ function InnerWrapper({embed}: Props) {
7779
isActive &&
7880
(playerStatus === 'waitingToPlayAtSpecifiedRate' ||
7981
playerStatus === 'loading')
82+
const isSwitching = playerStatus === 'switching'
83+
const showOverlay = !isActive || isLoading || isSwitching
8084

8185
// send error up to error boundary
8286
const [error, setError] = useState<Error | PlayerError | null>(null)
@@ -130,6 +134,7 @@ function InnerWrapper({embed}: Props) {
130134
player.play()
131135
}
132136
} else {
137+
setPlayerStatus('switching')
133138
player.muted = true
134139
if (player.playing) {
135140
player.pause()
@@ -148,48 +153,47 @@ function InnerWrapper({embed}: Props) {
148153
setIsFullscreen={setIsFullscreen}
149154
/>
150155
) : null}
151-
{!isActive || isLoading ? (
152-
<View
153-
style={[
154-
{
155-
position: 'absolute',
156-
top: 0,
157-
bottom: 0,
158-
left: 0,
159-
right: 0,
160-
},
161-
]}>
162-
<Image
163-
source={{uri: embed.thumbnail}}
164-
alt={embed.alt}
165-
style={a.flex_1}
166-
contentFit="cover"
167-
accessibilityIgnoresInvertColors
168-
/>
169-
<Button
170-
style={[a.absolute, a.inset_0]}
171-
onPress={() => {
172-
setActiveSource(embed.playlist, viewId)
173-
}}
174-
label={_(msg`Play video`)}
175-
color="secondary">
176-
{isLoading ? (
177-
<View
178-
style={[
179-
a.rounded_full,
180-
a.p_xs,
181-
a.absolute,
182-
{top: 'auto', left: 'auto'},
183-
{backgroundColor: 'rgba(0,0,0,0.5)'},
184-
]}>
185-
<Loader size="2xl" style={{color: 'white'}} />
186-
</View>
187-
) : (
188-
<PlayButtonIcon />
189-
)}
190-
</Button>
191-
</View>
192-
) : null}
156+
<View
157+
style={[
158+
{
159+
position: 'absolute',
160+
top: 0,
161+
bottom: 0,
162+
left: 0,
163+
right: 0,
164+
display: showOverlay ? 'flex' : 'none',
165+
},
166+
]}>
167+
<Image
168+
source={{uri: embed.thumbnail}}
169+
alt={embed.alt}
170+
style={a.flex_1}
171+
contentFit="cover"
172+
accessibilityIgnoresInvertColors
173+
/>
174+
<Button
175+
style={[a.absolute, a.inset_0]}
176+
onPress={() => {
177+
setActiveSource(embed.playlist, viewId)
178+
}}
179+
label={_(msg`Play video`)}
180+
color="secondary">
181+
{isLoading ? (
182+
<View
183+
style={[
184+
a.rounded_full,
185+
a.p_xs,
186+
a.absolute,
187+
{top: 'auto', left: 'auto'},
188+
{backgroundColor: 'rgba(0,0,0,0.5)'},
189+
]}>
190+
<Loader size="2xl" style={{color: 'white'}} />
191+
</View>
192+
) : (
193+
<PlayButtonIcon />
194+
)}
195+
</Button>
196+
</View>
193197
</VisibilityView>
194198
)
195199
}

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12416,7 +12416,7 @@ expo-updates@~0.25.14:
1241612416

1241712417
"expo-video@https://github.com/bluesky-social/expo/raw/expo-video-1.2.4-patch/packages/expo-video/expo-video-v1.2.4.tgz":
1241812418
version "1.2.4"
12419-
resolved "https://github.com/bluesky-social/expo/raw/expo-video-1.2.4-patch/packages/expo-video/expo-video-v1.2.4.tgz#584c17e34f59cb018eed2f4f408b6c94e2a1910f"
12419+
resolved "https://github.com/bluesky-social/expo/raw/expo-video-1.2.4-patch/packages/expo-video/expo-video-v1.2.4.tgz#15af07368c72cb847124be9922d5c7a3fe4293a4"
1242012420

1242112421
expo-web-browser@~13.0.3:
1242212422
version "13.0.3"

0 commit comments

Comments
 (0)