[$175] 1st point flashes briefly after Drag and Drop the Progess bar
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:
- Open App
- Go to any chat
- Upload video which is more than 1 minutes
- Play the video
- 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
Applause Internal Information Exported by: Svetlana Lazutkina Bug ID: 7293285
Upwork Automation - Do Not Edit
- Upwork Job URL: https://www.upwork.com/jobs/~022113269498547667182
- Upwork Job ID: 2113269498547667182
- Last Price Increase: 2026-10-22
Issue Owner
Current Issue Owner: @FitseTLT
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
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.
- When the drag starts,
ProgressBarpauses the video. Pausing setstimeUpdateEventIntervalto0, so the player stops sending time updates (BaseVideoPlayer.tsx:296). seekPositiononly setsplayer.currentTime. It does not update React state, and on Android a seek sends notimeUpdate(VideoPlayerControls/index.tsx:129).- On release,
onFinalizecallssetIsSliderPressed(false). The effect then resets the bar from the oldposition(the pre-drag time). That reset is the flash (ProgressBar/index.tsx:82-87). playVideo()then resumes playback. The interval turns back on, and the firsttimeUpdatemoves 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:
- Add a
seekTargetPositionstate (defaultnull). - Pass
position={seekTargetPosition ?? currentTime ?? 0}toVideoPlayerControls. - When the user seeks, set
seekTargetPositionto the new time as well as settingplayer.currentTime. For example, pass anonSeekcallback down, or moveseekPositionup. - Clear
seekTargetPositiononce the reportedcurrentTimeis 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
positioncomes from thetimeUpdateevent (BaseVideoPlayer.tsx:105) and is passed down atBaseVideoPlayer.tsx:653.- In expo-video on Android,
IntervalUpdateClockstops when the interval is0. When re-enabled, it sends one update immediately. ThecurrentTimesetter only queuesseekToand sends no event. - Do not force a
timeUpdateby toggling the interval during render. The comment atBaseVideoPlayer.tsx:295warns that this re-entersuseEventon 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.
Triggered auto assignment to Contributor-plus team member for initial proposal review - @thesahindia (External)
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 (
isSliderPressedgoesfalse), auseEffectimmediately resumes drivingprogressWidthfrom thepositionprop, assliderWidth * 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 intoprogressWidthand 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
setTimeoutafter release: This is fragile, because seek latency varies by device and network, and it still flashes on slow seeks. - Stop syncing
progressWidthfrompositionentirely and animate it independently: This duplicates playback state and can drift from the real position. - Debounce
positionupdates: This hides legitimate updates and adds visible lag during normal playback.
Testing
- On Android, open a chat and upload or play a video longer than 1 minute.
- 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.
- Repeat while the video is paused, and drag backwards as well. Seek to the very end and to the very start.
- Tap-seek on the bar and confirm it still updates correctly.
- Let the video play normally and confirm the thumb advances smoothly.
- Regression-check iOS, web and mWeb for the same flows.
- Add a unit test for the progress bar that simulates a gesture end followed by a stale
positionprop. It should assert thatprogressWidthis unchanged untilpositionis within tolerance of the seek target.
Job added to Upwork: https://www.upwork.com/jobs/~022113269498547667182
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:
- When dragging starts,
onBeginsetssetIsSliderPressed(true), pauses the video, and updatesprogressWidth.set(progress). - As the user scrubs,
seekPosition(newPosition)assignsvideoPlayerRef.current.currentTime = newPosition. - In
expo-video(particularly on Android native via ExoPlayer), seeking is asynchronous and does not emit a synchronoustimeUpdateevent. Furthermore, while the video is paused during the scrub,timeUpdateEventIntervalis0(BaseVideoPlayer.tsx:296), which halts periodic playback updates. - When the user releases the slider,
onFinalizeexecutes:setIsSliderPressed(false); - In
ProgressBar/index.tsx:82-87:
BecauseuseEffect(() => { if (isSliderPressed) { return; } progressWidth.set(getProgress(position, duration)); }, [duration, isSliderPressed, position, progressWidth]);isSliderPressedbecomesfalse, thisuseEffectexecutes immediately. At this exact moment, the parentBaseVideoPlayerhas not yet received a newtimeUpdateevent, so the incomingpositionprop is still the stale pre-drag time (or0). - The effect immediately rewrites
progressWidthwith the staleposition, causing the thumb to jump back to the origin. Milliseconds later,playVideo()resumes, the player emits the seekedtimeUpdate, 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:
- 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.
- Defensive Safety Timeout: The 1.5-second timeout ensures that if the video is paused or buffering, the bar never freezes permanently.
- Contained entirely within
ProgressBar: No refactoring ofBaseVideoPlayeror context providers is required, keeping diff minimal and isolated.
What alternative solutions did you explore? (Optional)
- MelvinBot's proposal to add
seekTargetPositionstate toBaseVideoPlayerand 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 inProgressBarcleanly 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
ProgressBarwithduration={100},position={10}. - Trigger pan gesture to progress
50%and finalize. - Simulate an incoming prop update with stale
position={10}:- Assert that
progressWidthremains50and does NOT snap back to10.
- Assert that
- Simulate incoming prop update with updated
position={50.1}:- Assert that
progressWidthsyncs with the updated position.
- Assert that
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
@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:
- Performance regression (60 fps re-renders): Melvin proposes lifting a
seekTargetPositionstate intoBaseVideoPlayerand passing callbacks down. Scrubbing triggers seeks continuously on every pan gesture frame, meaning updating state inBaseVideoPlayerwould cause unnecessary, heavy re-renders of the entire player shell and native video view during drag. - Fragile threshold & coarse keyframes: Melvin relies on clearing the target only when
currentTimereaches within a hardcoded0.5stolerance. 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. - 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:
progressWidthis already at the dropped position on release; the flash only occurs becauseisSliderPressedbecomingfalsecauses the effect to re-run and overwriteprogressWidthwith the unchanged, pre-seekposition.- By simply ignoring the effect sync when
positionhas 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?
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]);
- During dragging,
progressBarInteractionupdatesprogressWidth.set(progress)directly and callsscheduleOnRN(seekPosition, (progress * duration) / 100). - When the user drops/releases the slider,
onFinalizeexecutes and callssetIsSliderPressed(false). - The state update from
isSliderPressed = truetoisSliderPressed = falseimmediately triggers a re-render ofProgressBar. - The
useEffecton lines 82–87 includesisSliderPressedin its dependency array. - Because native video seeking (via ExoPlayer on Android, AVPlayer on iOS, or HTML5 video on Web) is asynchronous, the incoming
positionprop at the exact momentisSliderPressedbecomesfalseis still the stale, pre-drag playback position (e.g. 0s or near the start). - The
useEffectimmediately re-runs and executesprogressWidth.set(getProgress(position, duration))with the staleposition, instantly resetting the thumb back to the start. - A few frames later, the native video engine completes the seek and emits a playback status update, providing the new
positionprop 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)):
- In
onBegin, recorddragStartPositionRef.current = position. - In
useEffect, ifdragStartPositionRef.current !== nullandposition === dragStartPositionRef.current, ignore the sync:progressWidthis already at the released position, and the native player has not yet updatedposition. - As soon as the player reports the new position (
position !== dragStartPositionRef.current), synchronizeprogressWidthand resetdragStartPositionRef.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 inProgressBarusing a lightweight ref. - No hardcoded timers or tolerances: Avoids arbitrary
0.5sthresholds 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:
- Drop Thumb Flash Prevention:
- Mount
ProgressBaratposition = 0, duration = 60. - Trigger
onBeginand scrub to 50% (progressWidth= 50). - Trigger
onFinalize(isSliderPressedbecomesfalse), leavingpositionprop at0. - Assert
progressWidthremains at50%and is not overwritten with0%.
- Mount
- Seek Completion Sync:
- Update
positionprop to30. - Assert
progressWidthupdates to50%((30 / 60) * 100) anddragStartPositionRefis cleared.
- Update
- Normal Playback Progress:
- Advance
positionprop periodically during regular playback without interaction; assertprogressWidthupdates synchronously.
- Advance
What alternative solutions did you explore? (Optional)
- Lifting
seekTargetPositionstate toBaseVideoPlayer: Rejected because updating state inBaseVideoPlayeron every pan gesture frame triggers heavy 60fps re-renders of the root player and native video view during scrubbing. setTimeoutdelay before synchronizing: Rejected as fragile because seek completion latency varies significantly based on device performance, network buffering, and video encoding keyframe intervals.
✅ Contributor details stored successfully. Thank you for contributing to Expensify!
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:
- When the user begins dragging the progress bar (
onBeginatProgressBar/index.tsx#L59-L65),setIsSliderPressed(true)andpauseVideo()are called, andprogressBarInteractionupdates the shared valueprogressWidth.set(progress)directly on the UI thread while schedulingseekPosition((progress * duration) / 100)on the JS thread. - When
pauseVideo()runs, theplayingChangelistener insrc/components/VideoPlayer/BaseVideoPlayer.tsx#L260-L267setsvideoPlayerRef.current.timeUpdateEventInterval = 0. In addition, nativeexpo-video(ExoPlayeron Android) seeks asynchronously whenvideoPlayerRef.current.currentTime = newPositionis assigned (VideoPlayerControls/index.tsx#L118). Consequently,currentTimeinBaseVideoPlayer.tsx(#L94) — which is passed toProgressBarasposition— still holds the stale pre-drag timestamp (the 1st point) throughout the drag. - When the user releases the gesture (
onFinalizeatProgressBar/index.tsx#L69-L77),setIsSliderPressed(false)triggers an immediate React re-render beforeplayVideo()inonSeekEnd(BaseVideoPlayer.tsx#L569-L576) has resumed native playback and emitted a newtimeUpdateevent. - On that re-render, the
useEffectinProgressBar/index.tsx#L79-L84runs becauseisSliderPressedchanged fromtruetofalse:
BecauseuseEffect(() => { if (isSliderPressed) { return; } progressWidth.set(getProgress(position, duration)); }, [duration, isSliderPressed, position, progressWidth]);positionis still the stale pre-drag timestamp,progressWidth.set(getProgress(position, duration))snaps the progress bar back to the 1st point until the first post-seektimeUpdateevent 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,
progressWidthalready holds the exact target percentage set byprogressBarInteraction. On the re-render caused bysetIsSliderPressed(false),position === stalePositionOnReleaseRef.current, souseEffectreturns early instead of snapping back to the 1st point. As soon as playback resumes and the first post-seektimeUpdatearrives with the newposition,stalePositionOnReleaseRef.currentis cleared and normal tracking continues. - Paused video: When the video was paused before dragging (
shouldResumeAfterSeek === false),timeUpdateEventIntervalremains0while paused, so keeping the early return whileposition === stalePositionOnReleaseRef.currentalso prevents the progress bar from snapping back to the old position while paused. - Dropped at the exact same position:
progressWidthis already atgetProgress(position, duration)fromprogressBarInteraction, so returning early keeps the bar at the right position.
What alternative solutions did you explore? (Optional)
- Calling
setCurrentTime(newPosition)insideseekPositioninBaseVideoPlayer.tsx: BecauseseekPositionis called on every panonUpdateframe while dragging (ProgressBar/index.tsx#L48), calling a React state setter inBaseVideoPlayeron every gesture frame would trigger full React re-renders ofBaseVideoPlayerandVideoPlayerControlsat 60fps during scrubbing. Keeping the stale-position guard insideProgressBar/index.tsxviauseRefavoids extra re-renders during gesture updates.
📣 @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:
- Make sure you've read and understood the contributing guidelines.
- 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.
- 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.
- Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details.
Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>
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:
- When the user starts dragging the progress bar (
onBegin, line 61),setIsSliderPressed(true)is called andpauseVideo()pauses playback (which setstimeUpdateEventInterval = 0insrc/components/VideoPlayer/BaseVideoPlayer.tsx:296). - During the drag (
onUpdate, line 68),progressBarInteractionupdates the visualprogressWidthshared value immediately (progressWidth.set(progress)) and invokesseekPosition((progress * duration) / 100), which setsvideoPlayerRef.current.currentTime = newPosition(src/components/VideoPlayer/VideoPlayerControls/index.tsx:129). However, on Androidexpo-videoseeks asynchronously and does not emit atimeUpdateevent synchronously while paused, so thepositionprop passed intoProgressBarstill holds the stale pre-seek value (0when dragging from the start, or a slightly advanced pre-pause frame). - 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-seektimeUpdatewith the updatedcurrentTime. - On that re-render, the
useEffectat lines 82–87 seesisSliderPressed === falsewhilepositionis still at the pre-seek timestamp (0), and immediately executesprogressWidth.set(getProgress(position, duration)). This snapsprogressWidthback to0%(the 1st point) untilplayVideo()resumes playback and the first post-seektimeUpdateevent arrives with the newposition.
What changes do you think we should make in order to solve the problem?
In src/components/VideoPlayer/VideoPlayerControls/ProgressBar/index.tsx:
- Track
preSeekPositionRef = useRef<number | null>(null)(captured inonBegin) andpendingSeekTargetRef = useRef<number | null>(null)(updated inprogressBarInteractionto(progress * duration) / 100). - In the
useEffectthat syncsprogressWidthfrompositionwhen!isSliderPressed, ifpendingSeekTargetRef.current !== null:- Check whether
positionis still stuck nearpreSeekPositionRef.current(Math.abs(position - preSeekPosition) < 0.25) while the requested seek target is away frompreSeekPosition(Math.abs(targetPosition - preSeekPosition) >= 0.25). - If so, return early without overwriting
progressWidthwith the stale pre-seekposition(which also ignores any late pre-pausetimeUpdatetick within< 0.25sof the drag start). - Once
positionmoves past the pre-seek window (or when the user intentionally sought back topreSeekPosition), clear both refs and syncprogressWidth.set(getProgress(position, duration)).
- Check whether
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-flighttimeUpdatetick arrives right aspauseVideo()runs (advancingpositionby0.1sfrom0.0sto0.1s), strict equality fails and still flashes back near the 1st point. CheckingMath.abs(position - preSeekPosition) < 0.25 && Math.abs(targetPosition - preSeekPosition) >= 0.25absorbs any in-flight0.1spre-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 than0.5saway fromtargetPosition, causing a target-proximity check to stay locked during playback.
⚠️ Invalid email. Please make sure to create an Expensify account with this email first here.
@thesahindia Eep! 4 days overdue now. Issues have feelings too...
@thesahindia 6 days overdue. This is scarier than being forced to listen to Vogon poetry!
@FitseTLT Whoops! This issue is 2 days overdue. Let's get this updated quick!
@FitseTLT Whoops! This issue is 2 days overdue. Let's get this updated quick!
@FitseTLT Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!
Reviewing tomorrow