Repository navigation
Conversation
…he anchor out of the rendered window
…tems it compensates for
Author
|
I have signed the CLA. |
This branch has not been deployed
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.
Problem
When a measurement changes item sizes above the anchor,
RecyclerView's layout effect seesmodifyChildrenLayout(...) === trueand re-renders (setRenderId) so the items move. The scroll anchor (ScrollAnchor.scrollBy, compensated natively bymaintainVisibleContentPosition) is only moved later, inapplyOffsetCorrection, once a pass has nothing left to re-render — i.e. one commit after the items moved. A frame drawn between the two commits shows the content displaced by the correction, then snapping back. On a fast device this is rarely visible; on a slow one it is a hitch on every measurement while scrolling (each newly measured item above the viewport).Fix
applyOffsetCorrectionintoshiftAnchor(hasDataChanged).applyAnchorShift()returned byuseRecyclerViewController: applies only the anchor shift, for measurements only (data length unchanged), and returns the shift.RecyclerViewcallsapplyAnchorShift()right beforesetRenderId(...)in the branch that re-renders after a measurement, so the anchor moves in the same commit as the items and the native side compensates in the same frame.ignoreScrollEvents); pending scroll callbacks are left for the render they wait on.firstVisibleItemRecordedLayout: the "anchor still in view" test from PR 2 now uses the anchor as recorded. After an early shift the stored layout has moved but the JS scroll offset only catches up with the next native scroll event; comparing the two would turn away an anchor that is still on screen and lose a later correction in the same pass.Tests
Added to
src/__tests__/useRecyclerViewController.test.tsx(on top of PR 2's file):Expected: 1250, Received: 1200), which is whyfirstVisibleItemRecordedLayoutexists.ignoreScrollEvents.RecyclerView.tsxcallsapplyAnchorShift()right beforesetRenderId(. This reads the source file; happy to drop it or replace it with a mountedRecyclerViewtest if you prefer.All 7 tests in the file fail on PR 2 alone (no
applyAnchorShift) and pass with this change. Verified locally on the publishedsrcof 2.3.3 with PRs 1–3 applied: 13/13 tests in the touched test files pass;tscreports no new errors outside the test file's Node imports (fs,path;src/__tests__is excluded from the build's typecheck).Notes
scrollTo, now called from the same place.