App icon indicating copy to clipboard operation
App copied to clipboard

[$175] 1st point flashes briefly after Drag and Drop the Progess bar

Open applause-bot[bot] opened this issue 1 month ago • 44 comments

If you haven’t already, check out our contributing guidelines for onboarding. To join our Slack channel, fill out this form.


Version Number: 9.5.16-0 Reproducible in staging?: Yes Reproducible in production?: Yes If this was caught during regression testing, add the test name, ID and link from BrowserStack: https://github.com/Expensify/App/pull/103455 Email or phone of affected tester (no customers): [email protected] Issue reported by: Applause Internal Team Bug source: Pull Request QA execution Device used: realme C21y / android 11 App Component: Other

Action Performed:

  1. Open App
  2. Go to any chat
  3. Upload video which is more than 1 minutes
  4. Play the video
  5. Drag and drop the progress bar at more than 30 seconds from start

Expected Result:

1st point should not flashes after dropping the progress bar

Actual Result:

1st point flashes briefly after Drag and Drop the Progess bar

Workaround:

Unknown

Platforms:

  • [x] Android: App
  • [ ] Android: mWeb Chrome
  • [ ] iOS: App
  • [ ] iOS: mWeb Safari
  • [ ] iOS: mWeb Chrome
  • [ ] Windows: Chrome
  • [ ] MacOS: Chrome Safari

Screenshots/Videos

https://github.com/user-attachments/assets/3086d786-c063-4f73-bcc4-3dd66503b593

View all open jobs on GitHub

Applause Internal Information Exported by: Svetlana Lazutkina Bug ID: 7293285

Upwork Automation - Do Not Edit
Issue OwnerCurrent Issue Owner: @FitseTLT

applause-bot[bot] avatar Oct 22 '26 13:10 applause-bot[bot]

While Applause doesn't embed attachments for this bug, here are the links for quick view: https://platform.applause.com/services/links/v1/external/7985e916810319e229f117ea91d6e545efd906a681761049b55008ff4b60d064

applause-bot[bot] avatar Oct 22 '26 13:10 applause-bot[bot]

Proposal

Please re-state the problem that we are trying to solve in this issue.

On Android, when you drag the video progress bar and release it, the bar briefly jumps back to where it was before the drag. Then it moves to the new spot.

What is the root cause of that problem?

The progress bar shows the player's reported position, and that value is stale when you release the bar.

  1. When the drag starts, ProgressBar pauses the video. Pausing sets timeUpdateEventInterval to 0, so the player stops sending time updates (BaseVideoPlayer.tsx:296).
  2. seekPosition only sets player.currentTime. It does not update React state, and on Android a seek sends no timeUpdate (VideoPlayerControls/index.tsx:129).
  3. On release, onFinalize calls setIsSliderPressed(false). The effect then resets the bar from the old position (the pre-drag time). That reset is the flash (ProgressBar/index.tsx:82-87).
  4. playVideo() then resumes playback. The interval turns back on, and the first timeUpdate moves the bar to the new spot.

This bug is not caused by Migrate standalone pan gestures to Gesture Handler 3 hooks. That PR only renamed the gesture API in ProgressBar, which matches QA reproducing the bug in production. Web has the same logic, but there the time update arrives almost instantly, so the flash is hard to see.

What changes do you think we should make in order to solve the problem?

Show the seek target optimistically until the player catches up. Make this change in BaseVideoPlayer so the bar and the elapsed-time label both stay correct:

  1. Add a seekTargetPosition state (default null).
  2. Pass position={seekTargetPosition ?? currentTime ?? 0} to VideoPlayerControls.
  3. When the user seeks, set seekTargetPosition to the new time as well as setting player.currentTime. For example, pass an onSeek callback down, or move seekPosition up.
  4. Clear seekTargetPosition once the reported currentTime is close to the target (for example, within 0.5 s). Do not clear it on the first update, because one stale update may still be in flight.

This also covers dragging while the video is paused. In that case, playback never resumes, so the bar may stay at the old spot. I found this in the code but did not test it.

What alternative solutions did you explore? (Optional)

You could fix only ProgressBar: keep the last dragged value in a shared value, and skip the reset effect while position is still far from it. This fixes the bar but leaves the elapsed-time label stale.

Investigation details
  • position comes from the timeUpdate event (BaseVideoPlayer.tsx:105) and is passed down at BaseVideoPlayer.tsx:653.
  • In expo-video on Android, IntervalUpdateClock stops when the interval is 0. When re-enabled, it sends one update immediately. The currentTime setter only queues seekTo and sends no event.
  • Do not force a timeUpdate by toggling the interval during render. The comment at BaseVideoPlayer.tsx:295 warns that this re-enters useEvent on web.
  • I traced this in the code and did not reproduce it on a device. The bug is Android-only, and this run could only test on web.

Next Steps for Contributor+ team: To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/104740) to create a draft PR. To refine: @MelvinBot <your feedback> To reject: Explain why you are rejecting Melvin's proposal.


view run

MelvinBot avatar Oct 22 '26 14:10 MelvinBot

Triggered auto assignment to Contributor-plus team member for initial proposal review - @thesahindia (External)

melvin-bot[bot] avatar Oct 22 '26 14:10 melvin-bot[bot]

Proposal

Please re-state the problem that we are trying to solve in this issue.

On Android, when a user drags the video progress bar to a later point (for example past 30 seconds) and releases it, the slider thumb briefly jumps back to the start (the "1st point") and then returns to the dropped position. The thumb should stay where the user released it.

What is the root cause of that problem?

I couldn't open the repo, and Kimi's analysis was empty, so this rests on how the video player's progress bar is structured. The file is probably VideoPlayerControls/ProgressBar, and the exact names may differ.

  • The thumb and fill width come from a reanimated shared value, progressWidth. While the user drags, the pan gesture writes to it directly.
  • When the gesture finalizes (isSliderPressed goes false), a useEffect immediately resumes driving progressWidth from the position prop, as sliderWidth * position / duration.
  • The seek is asynchronous. On release the player is still reporting its old or reset position (0, or a stale value, while it seeks and buffers). The effect therefore writes that stale value into progressWidth and the thumb snaps back to the start.
  • The next playback status update arrives with the seeked position, and the thumb jumps forward again. This is the flash in the video.

The bug is a race between handing control back from the gesture to the position prop and the player confirming the seek.

What changes do you think we should make in order to solve the problem?

After release, keep the thumb at the dropped position and ignore incoming position updates until the player reports a position close to the seek target. Add a safety timeout so the bar can't freeze if the player never reports that position.

const pendingSeekMs = useRef<number | null>(null);
const pendingSeekTimeout = useRef<ReturnType<typeof setTimeout> | null>(null);
const SEEK_SYNC_TOLERANCE_MS = 1000;
const SEEK_SYNC_TIMEOUT_MS = 1500;

const clearPendingSeek = () => {
    pendingSeekMs.current = null;
    if (pendingSeekTimeout.current) {
        clearTimeout(pendingSeekTimeout.current);
        pendingSeekTimeout.current = null;
    }
};

// in the pan gesture
.onFinalize(() => {
    const target = (progressWidth.get() / sliderWidth) * duration;
    pendingSeekMs.current = target;
    pendingSeekTimeout.current = setTimeout(clearPendingSeek, SEEK_SYNC_TIMEOUT_MS);
    setIsSliderPressed(false);
    // existing resume-playback logic
})

// sync effect
useEffect(() => {
    if (isSliderPressed) {
        return;
    }
    if (pendingSeekMs.current !== null) {
        if (Math.abs(position - pendingSeekMs.current) > SEEK_SYNC_TOLERANCE_MS) {
            return; // stale position from before the seek completed, keep the thumb where the user dropped it
        }
        clearPendingSeek();
    }
    progressWidth.set(duration ? (sliderWidth * position) / duration : 0);
}, [position, duration, sliderWidth, isSliderPressed]);

useEffect(() => clearPendingSeek, []); // cleanup on unmount

Also check seekPosition in BaseVideoPlayer/PlaybackContext. It should set the local position state to the target immediately, so the prop agrees with the thumb as soon as the user releases. Make sure nothing resets position to 0 during seek or buffering, such as an onPlaybackStatusUpdate that reports positionMillis: 0 while loading.

What alternative solutions did you explore? (Optional)

  • Delay the effect with a fixed setTimeout after release: This is fragile, because seek latency varies by device and network, and it still flashes on slow seeks.
  • Stop syncing progressWidth from position entirely and animate it independently: This duplicates playback state and can drift from the real position.
  • Debounce position updates: This hides legitimate updates and adds visible lag during normal playback.

Testing

  1. On Android, open a chat and upload or play a video longer than 1 minute.
  2. Play it, then drag the progress bar to more than 30 seconds and release. The thumb must not flash to the start, and playback should continue from the dropped position.
  3. Repeat while the video is paused, and drag backwards as well. Seek to the very end and to the very start.
  4. Tap-seek on the bar and confirm it still updates correctly.
  5. Let the video play normally and confirm the thumb advances smoothly.
  6. Regression-check iOS, web and mWeb for the same flows.
  7. Add a unit test for the progress bar that simulates a gesture end followed by a stale position prop. It should assert that progressWidth is unchanged until position is within tolerance of the seek target.

Abdallah-1551 avatar Oct 22 '26 14:10 Abdallah-1551

Job added to Upwork: https://www.upwork.com/jobs/~022113269498547667182

melvin-bot[bot] avatar Oct 22 '26 14:10 melvin-bot[bot]

Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~0170d6b02e9440e604

Proposal

Please re-state the problem that we are trying to solve in this issue.

On Android, when dragging and dropping the video progress bar slider to seek to a new timestamp, the progress bar thumb/fill briefly snaps/flashes back to its starting (pre-drag) position before advancing to the seeked position.

What is the root cause of that problem?

In src/components/VideoPlayer/VideoPlayerControls/ProgressBar/index.tsx:

  1. When dragging starts, onBegin sets setIsSliderPressed(true), pauses the video, and updates progressWidth.set(progress).
  2. As the user scrubs, seekPosition(newPosition) assigns videoPlayerRef.current.currentTime = newPosition.
  3. In expo-video (particularly on Android native via ExoPlayer), seeking is asynchronous and does not emit a synchronous timeUpdate event. Furthermore, while the video is paused during the scrub, timeUpdateEventInterval is 0 (BaseVideoPlayer.tsx:296), which halts periodic playback updates.
  4. When the user releases the slider, onFinalize executes:
    setIsSliderPressed(false);
    
  5. In ProgressBar/index.tsx:82-87:
    useEffect(() => {
        if (isSliderPressed) {
            return;
        }
        progressWidth.set(getProgress(position, duration));
    }, [duration, isSliderPressed, position, progressWidth]);
    
    Because isSliderPressed becomes false, this useEffect executes immediately. At this exact moment, the parent BaseVideoPlayer has not yet received a new timeUpdate event, so the incoming position prop is still the stale pre-drag time (or 0).
  6. The effect immediately rewrites progressWidth with the stale position, causing the thumb to jump back to the origin. Milliseconds later, playVideo() resumes, the player emits the seeked timeUpdate, and the thumb jumps forward to the new target. This is the visible flash/stutter seen in the video.

What changes do you think we should make in order to solve the problem?

In src/components/VideoPlayer/VideoPlayerControls/ProgressBar/index.tsx: Track the pending seek position target across gesture finalization. Suppress resetting progressWidth from the position prop until the incoming position is within a reasonable sync threshold of the seek target (or cleared after a short safety timeout to prevent stalling if playback does not resume):

--- a/src/components/VideoPlayer/VideoPlayerControls/ProgressBar/index.tsx
+++ b/src/components/VideoPlayer/VideoPlayerControls/ProgressBar/index.tsx
@@ -7,7 +7,7 @@ import type {LayoutChangeEvent} from 'react-native';
 import type {PanGestureEvent} from 'react-native-gesture-handler';

-import React, {useEffect, useState} from 'react';
+import React, {useCallback, useEffect, useRef, useState} from 'react';
 import {GestureDetector, usePanGesture} from 'react-native-gesture-handler';
 import Animated, {useAnimatedStyle, useSharedValue} from 'react-native-reanimated';
 import {scheduleOnRN} from 'react-native-worklets';
@@ -28,6 +28,8 @@ type ProgressBarProps = {
     onSeekEnd?: (shouldResumeAfterSeek: boolean) => void;
 };

+const SEEK_SYNC_TOLERANCE_SECONDS = 0.5;
+
 function getProgress(currentPosition: number, maxPosition: number): number {
     return Math.min(Math.max((currentPosition / maxPosition) * 100, 0), 100);
 }
@@ -37,6 +39,15 @@ function ProgressBar({duration, position, seekPosition, onSeekStart, onSeekEnd}
     const [sliderWidth, setSliderWidth] = useState(1);
     const [isSliderPressed, setIsSliderPressed] = useState(false);
     const progressWidth = useSharedValue(0);
+    const pendingSeekTarget = useRef<number | null>(null);
+    const pendingSeekTimeout = useRef<NodeJS.Timeout | null>(null);
+
+    const clearPendingSeek = useCallback(() => {
+        pendingSeekTarget.current = null;
+        if (pendingSeekTimeout.current) {
+            clearTimeout(pendingSeekTimeout.current);
+            pendingSeekTimeout.current = null;
+        }
+    }, []);

     const onCheckIfVideoIsPlaying = (isPlaying: boolean) => {
         wasVideoPlayingOnCheck.set(isPlaying);
@@ -62,6 +73,8 @@ function ProgressBar({duration, position, seekPosition, onSeekStart, onSeekEnd}
             progressBarInteraction(event);
         },
         onFinalize: () => {
+            pendingSeekTarget.current = (progressWidth.get() * duration) / 100;
+            pendingSeekTimeout.current = setTimeout(clearPendingSeek, 1500);
             setIsSliderPressed(false);
             const shouldResumeAfterSeek = wasVideoPlayingOnCheck.get();
             onSeekEnd?.(shouldResumeAfterSeek);
@@ -83,6 +96,12 @@ function ProgressBar({duration, position, seekPosition, onSeekStart, onSeekEnd}
     useEffect(() => {
         if (isSliderPressed) {
             return;
         }
+        if (pendingSeekTarget.current !== null) {
+            if (Math.abs(position - pendingSeekTarget.current) > SEEK_SYNC_TOLERANCE_SECONDS) {
+                return;
+            }
+            clearPendingSeek();
+        }
         progressWidth.set(getProgress(position, duration));
-    }, [duration, isSliderPressed, position, progressWidth]);
+    }, [clearPendingSeek, duration, isSliderPressed, position, progressWidth]);

Why this solution is optimal:

  1. Completely eliminates the visual jump/flash: The slider thumb remains precisely where the user dropped it until the native player's playback position catches up to the target.
  2. Defensive Safety Timeout: The 1.5-second timeout ensures that if the video is paused or buffering, the bar never freezes permanently.
  3. Contained entirely within ProgressBar: No refactoring of BaseVideoPlayer or context providers is required, keeping diff minimal and isolated.

What alternative solutions did you explore? (Optional)

  • MelvinBot's proposal to add seekTargetPosition state to BaseVideoPlayer and pass down new props: Overcomplicates the architecture. Passing state through 3 component layers (BaseVideoPlayer -> VideoPlayerControls -> ProgressBar) creates unnecessary re-renders in the video player shell. Handling the visual latch directly in ProgressBar cleanly decouples slider animation state from playback loop state.

What automated tests can you add to prevent this from re-occurring?

In tests/unit/ProgressBarTest.tsx:

  • Render ProgressBar with duration={100}, position={10}.
  • Trigger pan gesture to progress 50% and finalize.
  • Simulate an incoming prop update with stale position={10}:
    • Assert that progressWidth remains 50 and does NOT snap back to 10.
  • Simulate incoming prop update with updated position={50.1}:
    • Assert that progressWidth syncs with the updated position.

camesenin avatar Oct 22 '26 14:10 camesenin

✅ Contributor details stored successfully. Thank you for contributing to Expensify!

melvin-bot[bot] avatar Oct 22 '26 14:10 melvin-bot[bot]

@thesahindia I was able to reproduce this issue consistently on Android and have a working fix ready. Before posting a full proposal, I wanted to highlight why MelvinBot's proposed approach has significant drawbacks and how we can solve this much more cleanly.

Why MelvinBot's approach isn't ideal:

  1. Performance regression (60 fps re-renders): Melvin proposes lifting a seekTargetPosition state into BaseVideoPlayer and passing callbacks down. Scrubbing triggers seeks continuously on every pan gesture frame, meaning updating state in BaseVideoPlayer would cause unnecessary, heavy re-renders of the entire player shell and native video view during drag.
  2. Fragile threshold & coarse keyframes: Melvin relies on clearing the target only when currentTime reaches within a hardcoded 0.5s tolerance. On Android (ExoPlayer), seeking snaps to sync keyframes which can often be 1–2s apart, causing the sync condition to fail and freeze the bar.
  3. Over-engineering: It unnecessarily touches three component layers (BaseVideoPlayer -> VideoPlayerControls -> ProgressBar) with prop drilling.

A cleaner, localized approach:

The issue can be completely resolved directly inside ProgressBar with ~7 lines of code:

  • progressWidth is already at the dropped position on release; the flash only occurs because isSliderPressed becoming false causes the effect to re-run and overwrite progressWidth with the unchanged, pre-seek position.
  • By simply ignoring the effect sync when position has not changed from the release point, the thumb stays firmly in place without any arbitrary tolerances, timers, or parent re-renders. It also handles seeking while paused seamlessly.

Demo Videos

  • Reproduction:

https://github.com/user-attachments/assets/d252a082-638d-454d-8581-169f43a34c04

  • Fix:

https://github.com/user-attachments/assets/8ce896dc-8c01-4a68-a5f7-f8edc35a93a4

Would you like me to submit the full proposal with the exact implementation details and proof?

emkhalid avatar Oct 24 '26 12:10 emkhalid

Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~01b6be874e7d6b47d1

Proposal

Please re-state the problem that we are trying to solve in this issue.

When dragging and dropping the video player progress bar (e.g. forward past 30 seconds), upon releasing the drag, the progress indicator/thumb briefly flashes/jumps back to the starting point (0s / 1st point) for a split second before jumping to the seeked position.

What is the root cause of that problem?

In src/components/VideoPlayer/VideoPlayerControls/ProgressBar/index.tsx:

const pan = usePanGesture({
    runOnJS: true,
    minDistance: 0,
    activateAfterLongPress: 0,
    onBegin: (event) => {
        setIsSliderPressed(true);
        ...
        progressBarInteraction(event);
    },
    onUpdate: (event) => {
        progressBarInteraction(event);
    },
    onFinalize: () => {
        setIsSliderPressed(false);
        ...
    },
});

useEffect(() => {
    if (isSliderPressed) {
        return;
    }
    progressWidth.set(getProgress(position, duration));
}, [duration, isSliderPressed, position, progressWidth]);
  1. During dragging, progressBarInteraction updates progressWidth.set(progress) directly and calls scheduleOnRN(seekPosition, (progress * duration) / 100).
  2. When the user drops/releases the slider, onFinalize executes and calls setIsSliderPressed(false).
  3. The state update from isSliderPressed = true to isSliderPressed = false immediately triggers a re-render of ProgressBar.
  4. The useEffect on lines 82–87 includes isSliderPressed in its dependency array.
  5. Because native video seeking (via ExoPlayer on Android, AVPlayer on iOS, or HTML5 video on Web) is asynchronous, the incoming position prop at the exact moment isSliderPressed becomes false is still the stale, pre-drag playback position (e.g. 0s or near the start).
  6. The useEffect immediately re-runs and executes progressWidth.set(getProgress(position, duration)) with the stale position, instantly resetting the thumb back to the start.
  7. A few frames later, the native video engine completes the seek and emits a playback status update, providing the new position prop and causing the visible snap/flash.

What changes do you think we should make in order to solve the problem?

We can solve this completely and surgically inside src/components/VideoPlayer/VideoPlayerControls/ProgressBar/index.tsx without touching parent components or adding arbitrary timeouts:

Track the pre-drag position with a ref (dragStartPositionRef = useRef<number | null>(null)):

  1. In onBegin, record dragStartPositionRef.current = position.
  2. In useEffect, if dragStartPositionRef.current !== null and position === dragStartPositionRef.current, ignore the sync: progressWidth is already at the released position, and the native player has not yet updated position.
  3. As soon as the player reports the new position (position !== dragStartPositionRef.current), synchronize progressWidth and reset dragStartPositionRef.current = null.
// src/components/VideoPlayer/VideoPlayerControls/ProgressBar/index.tsx
function ProgressBar({duration, position, seekPosition, onSeekStart, onSeekEnd}: ProgressBarProps) {
    const styles = useThemeStyles();
    const {pauseVideo, playVideo, checkIfVideoIsPlaying} = usePlaybackActionsContext();
    const [sliderWidth, setSliderWidth] = useState(1);
    const [isSliderPressed, setIsSliderPressed] = useState(false);
    const progressWidth = useSharedValue(0);
    const wasVideoPlayingOnCheck = useSharedValue(false);
    const dragStartPositionRef = useRef<number | null>(null);

    const onCheckIfVideoIsPlaying = (isPlaying: boolean) => {
        wasVideoPlayingOnCheck.set(isPlaying);
    };

    const progressBarInteraction = (event: PanGestureEvent) => {
        const progress = getProgress(event.x, sliderWidth);
        progressWidth.set(progress);
        scheduleOnRN(seekPosition, (progress * duration) / 100);
    };

    const onSliderLayout = (event: LayoutChangeEvent) => {
        setSliderWidth(event.nativeEvent.layout.width);
    };

    const pan = usePanGesture({
        runOnJS: true,
        minDistance: 0,
        activateAfterLongPress: 0,
        onBegin: (event) => {
            setIsSliderPressed(true);
            dragStartPositionRef.current = position;
            checkIfVideoIsPlaying(onCheckIfVideoIsPlaying);
            onSeekStart?.();
            pauseVideo();
            progressBarInteraction(event);
        },
        onUpdate: (event) => {
            progressBarInteraction(event);
        },
        onFinalize: () => {
            setIsSliderPressed(false);
            const shouldResumeAfterSeek = wasVideoPlayingOnCheck.get();
            onSeekEnd?.(shouldResumeAfterSeek);
            if (onSeekEnd || !shouldResumeAfterSeek) {
                return;
            }
            playVideo();
        },
    });

    useEffect(() => {
        if (isSliderPressed) {
            return;
        }
        // If position hasn't updated from the drag start point yet, do not overwrite the thumb's dropped position
        if (dragStartPositionRef.current !== null && position === dragStartPositionRef.current) {
            return;
        }
        dragStartPositionRef.current = null;
        progressWidth.set(getProgress(position, duration));
    }, [duration, isSliderPressed, position, progressWidth]);
...

Why this solution is superior:

  • Zero re-render overhead: No state is lifted to BaseVideoPlayer; the entire fix lives in ProgressBar using a lightweight ref.
  • No hardcoded timers or tolerances: Avoids arbitrary 0.5s thresholds that break on keyframe-quantized streams or slower Android devices.
  • Seamless paused seeking: Even when seeking while paused, the native player emits the seeked position upon completion, seamlessly transitioning without flicker.

What specific scenarios should we cover in automated tests?

In tests/unit/ProgressBarTest.tsx:

  1. Drop Thumb Flash Prevention:
    • Mount ProgressBar at position = 0, duration = 60.
    • Trigger onBegin and scrub to 50% (progressWidth = 50).
    • Trigger onFinalize (isSliderPressed becomes false), leaving position prop at 0.
    • Assert progressWidth remains at 50% and is not overwritten with 0%.
  2. Seek Completion Sync:
    • Update position prop to 30.
    • Assert progressWidth updates to 50% ((30 / 60) * 100) and dragStartPositionRef is cleared.
  3. Normal Playback Progress:
    • Advance position prop periodically during regular playback without interaction; assert progressWidth updates synchronously.

What alternative solutions did you explore? (Optional)

  1. Lifting seekTargetPosition state to BaseVideoPlayer: Rejected because updating state in BaseVideoPlayer on every pan gesture frame triggers heavy 60fps re-renders of the root player and native video view during scrubbing.
  2. setTimeout delay before synchronizing: Rejected as fragile because seek completion latency varies significantly based on device performance, network buffering, and video encoding keyframe intervals.

ADITYASINGH1206 avatar Oct 24 '26 13:10 ADITYASINGH1206

✅ Contributor details stored successfully. Thank you for contributing to Expensify!

melvin-bot[bot] avatar Oct 24 '26 13:10 melvin-bot[bot]

Proposal

Please re-state the problem that we are trying to solve in this issue.

In the video player (reproducible on Android), when dragging the progress bar from an initial timestamp (the "1st point") and dropping it at a new timestamp, the progress bar briefly flashes back to the 1st point before jumping to the newly selected position.

What is the root cause of that problem?

In src/components/VideoPlayer/VideoPlayerControls/ProgressBar/index.tsx:

  1. When the user begins dragging the progress bar (onBegin at ProgressBar/index.tsx#L59-L65), setIsSliderPressed(true) and pauseVideo() are called, and progressBarInteraction updates the shared value progressWidth.set(progress) directly on the UI thread while scheduling seekPosition((progress * duration) / 100) on the JS thread.
  2. When pauseVideo() runs, the playingChange listener in src/components/VideoPlayer/BaseVideoPlayer.tsx#L260-L267 sets videoPlayerRef.current.timeUpdateEventInterval = 0. In addition, native expo-video (ExoPlayer on Android) seeks asynchronously when videoPlayerRef.current.currentTime = newPosition is assigned (VideoPlayerControls/index.tsx#L118). Consequently, currentTime in BaseVideoPlayer.tsx (#L94) — which is passed to ProgressBar as position — still holds the stale pre-drag timestamp (the 1st point) throughout the drag.
  3. When the user releases the gesture (onFinalize at ProgressBar/index.tsx#L69-L77), setIsSliderPressed(false) triggers an immediate React re-render before playVideo() in onSeekEnd (BaseVideoPlayer.tsx#L569-L576) has resumed native playback and emitted a new timeUpdate event.
  4. On that re-render, the useEffect in ProgressBar/index.tsx#L79-L84 runs because isSliderPressed changed from true to false:
    useEffect(() => {
        if (isSliderPressed) {
            return;
        }
        progressWidth.set(getProgress(position, duration));
    }, [duration, isSliderPressed, position, progressWidth]);
    
    Because position is still the stale pre-drag timestamp, progressWidth.set(getProgress(position, duration)) snaps the progress bar back to the 1st point until the first post-seek timeUpdate event arrives and moves it back to the dropped position.

What changes do you think we should make in order to solve the problem?

In src/components/VideoPlayer/VideoPlayerControls/ProgressBar/index.tsx, record the position prop value at the moment the drag finishes in a useRef<number | null>(null) (stalePositionOnReleaseRef), and skip overwriting progressWidth in the useEffect until position actually updates to a new post-seek timestamp (or duration changes):

// src/components/VideoPlayer/VideoPlayerControls/ProgressBar/index.tsx
const [isSliderPressed, setIsSliderPressed] = useState(false);
const stalePositionOnReleaseRef = useRef<number | null>(null);
const progressWidth = useSharedValue(0);
const wasVideoPlayingOnCheck = useSharedValue(false);

const onSliderPressBegin = () => {
    stalePositionOnReleaseRef.current = null;
    setIsSliderPressed(true);
    onSeekStart?.();
};

const onSliderPressEnd = (shouldResume: boolean) => {
    stalePositionOnReleaseRef.current = position;
    setIsSliderPressed(false);
    onSeekEnd?.(shouldResume);
};

Update the gesture callbacks (onBegin / onFinalize at #L59-L77) to call scheduleOnRN(onSliderPressBegin) and scheduleOnRN(onSliderPressEnd, shouldResumeAfterSeek), and guard the useEffect at #L79-L84:

useEffect(() => {
    if (isSliderPressed) {
        return;
    }
    if (stalePositionOnReleaseRef.current !== null) {
        if (position === stalePositionOnReleaseRef.current) {
            return;
        }
        stalePositionOnReleaseRef.current = null;
    }
    progressWidth.set(getProgress(position, duration));
}, [duration, isSliderPressed, position, progressWidth]);

Why this works cleanly across all cases:

  • Playing video: When the user drops the scrubber, progressWidth already holds the exact target percentage set by progressBarInteraction. On the re-render caused by setIsSliderPressed(false), position === stalePositionOnReleaseRef.current, so useEffect returns early instead of snapping back to the 1st point. As soon as playback resumes and the first post-seek timeUpdate arrives with the new position, stalePositionOnReleaseRef.current is cleared and normal tracking continues.
  • Paused video: When the video was paused before dragging (shouldResumeAfterSeek === false), timeUpdateEventInterval remains 0 while paused, so keeping the early return while position === stalePositionOnReleaseRef.current also prevents the progress bar from snapping back to the old position while paused.
  • Dropped at the exact same position: progressWidth is already at getProgress(position, duration) from progressBarInteraction, so returning early keeps the bar at the right position.

What alternative solutions did you explore? (Optional)

  • Calling setCurrentTime(newPosition) inside seekPosition in BaseVideoPlayer.tsx: Because seekPosition is called on every pan onUpdate frame while dragging (ProgressBar/index.tsx#L48), calling a React state setter in BaseVideoPlayer on every gesture frame would trigger full React re-renders of BaseVideoPlayer and VideoPlayerControls at 60fps during scrubbing. Keeping the stale-position guard inside ProgressBar/index.tsx via useRef avoids extra re-renders during gesture updates.

xian96xx avatar Oct 25 '26 14:10 xian96xx

📣 @xian96xx! 📣 Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork. Please follow these steps:

  1. Make sure you've read and understood the contributing guidelines.
  2. Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
  3. Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
  4. Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details. Screen Shot 2022-11-16 at 4 42 54 PM Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>

melvin-bot[bot] avatar Oct 25 '26 14:10 melvin-bot[bot]

Proposal

Please re-state the problem that we are trying to solve in this issue.

When playing a video in full-screen mode on Android (and other platforms where native video seeking is asynchronous), dragging and dropping the video progress bar from the beginning (0:00) to a new timestamp causes the progress bar fill/thumb to briefly flash back to the 1st point (0:00) upon release before jumping back to the new position.

What is the root cause of that problem?

In src/components/VideoPlayer/VideoPlayerControls/ProgressBar/index.tsx:61-87:

  1. When the user starts dragging the progress bar (onBegin, line 61), setIsSliderPressed(true) is called and pauseVideo() pauses playback (which sets timeUpdateEventInterval = 0 in src/components/VideoPlayer/BaseVideoPlayer.tsx:296).
  2. During the drag (onUpdate, line 68), progressBarInteraction updates the visual progressWidth shared value immediately (progressWidth.set(progress)) and invokes seekPosition((progress * duration) / 100), which sets videoPlayerRef.current.currentTime = newPosition (src/components/VideoPlayer/VideoPlayerControls/index.tsx:129). However, on Android expo-video seeks asynchronously and does not emit a timeUpdate event synchronously while paused, so the position prop passed into ProgressBar still holds the stale pre-seek value (0 when dragging from the start, or a slightly advanced pre-pause frame).
  3. When the user releases the slider (onFinalize, line 71), setIsSliderPressed(false) triggers a synchronous React re-render before the native player has emitted a post-seek timeUpdate with the updated currentTime.
  4. On that re-render, the useEffect at lines 82–87 sees isSliderPressed === false while position is still at the pre-seek timestamp (0), and immediately executes progressWidth.set(getProgress(position, duration)). This snaps progressWidth back to 0% (the 1st point) until playVideo() resumes playback and the first post-seek timeUpdate event arrives with the new position.

What changes do you think we should make in order to solve the problem?

In src/components/VideoPlayer/VideoPlayerControls/ProgressBar/index.tsx:

  1. Track preSeekPositionRef = useRef<number | null>(null) (captured in onBegin) and pendingSeekTargetRef = useRef<number | null>(null) (updated in progressBarInteraction to (progress * duration) / 100).
  2. In the useEffect that syncs progressWidth from position when !isSliderPressed, if pendingSeekTargetRef.current !== null:
    • Check whether position is still stuck near preSeekPositionRef.current (Math.abs(position - preSeekPosition) < 0.25) while the requested seek target is away from preSeekPosition (Math.abs(targetPosition - preSeekPosition) >= 0.25).
    • If so, return early without overwriting progressWidth with the stale pre-seek position (which also ignores any late pre-pause timeUpdate tick within < 0.25s of the drag start).
    • Once position moves past the pre-seek window (or when the user intentionally sought back to preSeekPosition), clear both refs and sync progressWidth.set(getProgress(position, duration)).
diff --git a/src/components/VideoPlayer/VideoPlayerControls/ProgressBar/index.tsx b/src/components/VideoPlayer/VideoPlayerControls/ProgressBar/index.tsx
index 73e60d2..eb29257 100644
--- a/src/components/VideoPlayer/VideoPlayerControls/ProgressBar/index.tsx
+++ b/src/components/VideoPlayer/VideoPlayerControls/ProgressBar/index.tsx
@@ -5,7 +5,7 @@ import useThemeStyles from '@hooks/useThemeStyles';
 import type {LayoutChangeEvent} from 'react-native';
 import type {PanGestureEvent} from 'react-native-gesture-handler';
 
-import React, {useEffect, useState} from 'react';
+import React, {useEffect, useRef, useState} from 'react';
 import {GestureDetector, usePanGesture} from 'react-native-gesture-handler';
 import Animated, {useAnimatedStyle, useSharedValue} from 'react-native-reanimated';
 import {scheduleOnRN} from 'react-native-worklets';
@@ -38,6 +38,8 @@ function ProgressBar({duration, position, seekPosition, onSeekStart, onSeekEnd}:
     const [isSliderPressed, setIsSliderPressed] = useState(false);
     const progressWidth = useSharedValue(0);
     const wasVideoPlayingOnCheck = useSharedValue(false);
+    const pendingSeekTargetRef = useRef<number | null>(null);
+    const preSeekPositionRef = useRef<number | null>(null);
 
     const onCheckIfVideoIsPlaying = (isPlaying: boolean) => {
         wasVideoPlayingOnCheck.set(isPlaying);
@@ -45,8 +47,10 @@ function ProgressBar({duration, position, seekPosition, onSeekStart, onSeekEnd}:
 
     const progressBarInteraction = (event: PanGestureEvent) => {
         const progress = getProgress(event.x, sliderWidth);
+        const targetPosition = (progress * duration) / 100;
+        pendingSeekTargetRef.current = targetPosition;
         progressWidth.set(progress);
-        scheduleOnRN(seekPosition, (progress * duration) / 100);
+        scheduleOnRN(seekPosition, targetPosition);
     };
 
     const onSliderLayout = (event: LayoutChangeEvent) => {
@@ -59,6 +63,7 @@ function ProgressBar({duration, position, seekPosition, onSeekStart, onSeekEnd}:
         minDistance: 0,
         activateAfterLongPress: 0,
         onBegin: (event) => {
+            preSeekPositionRef.current = position;
             setIsSliderPressed(true);
             checkIfVideoIsPlaying(onCheckIfVideoIsPlaying);
             onSeekStart?.();
@@ -83,6 +88,16 @@ function ProgressBar({duration, position, seekPosition, onSeekStart, onSeekEnd}:
         if (isSliderPressed) {
             return;
         }
+        if (pendingSeekTargetRef.current !== null) {
+            const targetPosition = pendingSeekTargetRef.current;
+            const preSeekPosition = preSeekPositionRef.current;
+            const isStillAtPreSeekPosition = preSeekPosition !== null && Math.abs(position - preSeekPosition) < 0.25 && Math.abs(targetPosition - preSeekPosition) >= 0.25;
+            if (isStillAtPreSeekPosition) {
+                return;
+            }
+            pendingSeekTargetRef.current = null;
+            preSeekPositionRef.current = null;
+        }
         progressWidth.set(getProgress(position, duration));
     }, [duration, isSliderPressed, position, progressWidth]);
 

What alternative solutions did you explore? (Optional)

  • Checking exact equality (position === dragStartPosition) without a pre-seek window or target comparison: If a single in-flight timeUpdate tick arrives right as pauseVideo() runs (advancing position by 0.1s from 0.0s to 0.1s), strict equality fails and still flashes back near the 1st point. Checking Math.abs(position - preSeekPosition) < 0.25 && Math.abs(targetPosition - preSeekPosition) >= 0.25 absorbs any in-flight 0.1s pre-pause tick while still allowing intentional seeks back to the origin.
  • Requiring Math.abs(position - targetPosition) < 0.5: Native Android video decoders seek to the nearest keyframe, which can be more than 0.5s away from targetPosition, causing a target-proximity check to stay locked during playback.

shilo1979jk avatar Oct 26 '26 15:10 shilo1979jk

⚠️ Invalid email. Please make sure to create an Expensify account with this email first here.

melvin-bot[bot] avatar Oct 26 '26 15:10 melvin-bot[bot]

@thesahindia Eep! 4 days overdue now. Issues have feelings too...

melvin-bot[bot] avatar Oct 27 '26 21:10 melvin-bot[bot]

@thesahindia 6 days overdue. This is scarier than being forced to listen to Vogon poetry!

melvin-bot[bot] avatar Oct 29 '26 21:10 melvin-bot[bot]

@FitseTLT Whoops! This issue is 2 days overdue. Let's get this updated quick!

melvin-bot[bot] avatar Nov 02 '26 23:11 melvin-bot[bot]

@FitseTLT Whoops! This issue is 2 days overdue. Let's get this updated quick!

melvin-bot[bot] avatar Nov 03 '26 01:11 melvin-bot[bot]

@FitseTLT Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

melvin-bot[bot] avatar Nov 03 '26 03:11 melvin-bot[bot]

Reviewing tomorrow

FitseTLT avatar Nov 03 '26 08:11 FitseTLT