fix: player getting stuck on timer and exit

Fixed a race condition where the upnext countdown started and a user
cancelled/stop the current playback that they would exit the player but
the timer would still be running and then start playing the next episode
and you wouldn't be able to press back or exit out of it

Signed-off-by: Lance Chant <13349722+lancechant@users.noreply.github.com>
This commit is contained in:
Lance Chant
2026-05-30 10:03:19 +02:00
parent 4cc11403f8
commit 1cabbf087e
3 changed files with 48 additions and 5 deletions

View File

@@ -63,6 +63,7 @@ export const TVNextEpisodeCountdown: FC<TVNextEpisodeCountdownProps> = ({
const typography = useScaledTVTypography();
const { t } = useTranslation();
const progress = useSharedValue(0);
const cancelled = useSharedValue(false);
const onFinishRef = useRef(onFinish);
const { focused, handleFocus, handleBlur, animatedStyle } =
useTVFocusAnimation({
@@ -120,13 +121,15 @@ export const TVNextEpisodeCountdown: FC<TVNextEpisodeCountdownProps> = ({
return;
}
cancelled.value = false;
// Resume from current position
const remainingDuration = (1 - progress.value) * 8000;
progress.value = withTiming(
1,
{ duration: remainingDuration, easing: Easing.linear },
(finished) => {
if (finished) {
if (finished && !cancelled.value) {
runOnJS(onFinishRef.current)();
}
},
@@ -134,9 +137,10 @@ export const TVNextEpisodeCountdown: FC<TVNextEpisodeCountdownProps> = ({
// Cancel animation on unmount to prevent onFinish from firing after exit
return () => {
cancelled.value = true;
cancelAnimation(progress);
};
}, [show, isPlaying, progress]);
}, [show, isPlaying, progress, cancelled]);
const progressStyle = useAnimatedStyle(() => ({
width: `${progress.value * 100}%`,