Repository navigation
fix(indicator): keep the thumb under a finger that lands while the list scrolls - #20
Merged
Merged
Conversation
…st scrolls The pan tells the JS thread that a finger is on the track through runOnJS. Scroll events already in line on the JS thread when the finger landed still passed the handle's check and moved the thumb back to the list's old offset, away from the finger, until the finger moved far enough to activate the pan or lifted. It needs a busy JS thread, such as a fling through a heavy list. The pan now also keeps the flag in a shared value, set on the UI thread at touch down, and the handle sends the thumb's position there with runOnUI, where the check runs. The JS copy still gates the handle first: when the finger lifts, the list's scroll events from the drag report where the finger was a few frames before, and they must not restart the hide timer under a resting finger. Under Jest runOnJS runs at once, so the suite opts in to a fixture whose runOnJS calls wait while the test plays what the JS thread had in line. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…read IndicatorGrab keeps the JS thread busy for 40 ms on every scroll frame, as a heavy screen would, so the list's scroll events pile up there while it flings. Fling the list, then rest a finger on the track: the thumb must stay under it. On the previous indicator it went back to where the list was until the finger lifted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified for the scroll-indicator touch-handling change.
No open issues 🎉
What changed in this PR
Fixes FastScrollIndicator so queued list scroll reports cannot move the thumb away from a resting finger, while preserving protection against stale reports after lift.
Changes:
- Adds a UI-thread touch flag and guarded thumb updates, retaining the existing JS-thread check.
- Adds regression tests, a delayed-
runOnJSfixture, and a busy-thread example screen. - Updates testing guidance, handle conventions, and the backlog.
| File | Description |
|---|---|
src/FastScrollIndicator/FastScrollIndicator.tsx |
Guards list-driven thumb updates on the UI thread. |
src/FastScrollIndicator/__tests__/FastScrollIndicator.test.tsx |
Tests queued scroll reports at touch-down and lift. |
src/__fixtures__/jsThread.ts |
Adds controlled queuing of runOnJS calls for tests. |
example/src/screens.ts |
Adds the IndicatorGrab route type. |
example/src/NavigationTree.tsx |
Registers the new example screen. |
example/src/indicatorGrab/IndicatorGrab.tsx |
Demonstrates grabbing the indicator with a busy JS thread. |
example/src/ExamplesScreen.tsx |
Adds navigation to the new example. |
docs/unit-testing.md |
Documents the busy-thread fixture and its use. |
docs/backlog.md |
Records the fix and removes the resolved backlog item. |
CLAUDE.md |
Documents the complementary UI- and JS-thread guards. |
Review effort: Balanced
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The indicator's pan tells the JS thread that a finger is on the track through
runOnJS. That message waits behind any list scroll events already queued on the JS thread. On a busy JS thread, those events passed the handle's check and moved the thumb back to the list's old offset, away from the finger. It stayed there until the finger moved far enough to activate the pan, or lifted.Each copy of the flag covers one end of the touch:
The dots bar already checks on the UI thread. It needs no JS copy because its list stays still during a drag (
onScrollToIndexis debounced).Also in this PR:
src/__fixtures__/jsThread.tslets a test reproduce the JS thread's queue (see Evidence).docs/unit-testing.mddocuments the fixture, andCLAUDE.mddescribes the handle rule with both flags.Evidence
Unit tests. Under Jest
runOnJSruns at once, so the race could not happen in a test. With the new fixture,runOnJScalls made insidewhileJsThreadIsBusy(...)wait until whatever the test does on the JS thread has run, as calls queued behind it would on a device. The rest of Reanimated is the real one.Mutation check:
yarn test(110 passed, 1 todo),yarn typecheckandyarn lintpass.On a device.
The same side by side as a video:
before-after.mp4
One second into the hold:
Thumb read from every frame of the recordings (30 fps). The finger rests at y = 1872 px, and the track spans 501 to 2274 px.
main)Merge Danger
Door: two-way
The change is limited to the indicator's handle and pan. Reverting it restores the old behavior.
Blast Radius: indicator thumb
onScrollToOffsetPercentagecall now sends onerunOnUIinstead of writingtranslateYfrom JS. That costs the same: a JS write of a shared value is already scheduled onto the UI thread, on Reanimated 3 (runOnUIinmutables.ts) and on 2.12 (scheduleOnUIinMutableValue.cpp). The handle still reads no shared value from JS.onLayout.runOnJSwith a wrapper that can hold calls back; the rest of Reanimated stays real. The example screen and the fixture are not published.🤖 Generated with Claude Code