Skip to content

[iOS] Fix maintainVisibleContentPosition reusing a stale anchor - #60263

Open
lazerg wants to merge 1 commit into
react:mainfrom
lazerg:fix/issue-60260-mvcp-stale-anchor
Open

lazerg wants to merge 1 commit into
react:mainfrom
lazerg:fix/issue-60260-mvcp-stale-anchor

Conversation

@lazerg

@lazerg lazerg commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

On iOS, _prepareForMaintainVisibleScrollPosition returns early when there is no child at minIndexForVisible (or when maintainVisibleContentPosition is off), but it kept the anchor from the previous mount. _adjustForMaintainVisibleContentPosition then measured that old anchor against its old frame again and applied the same delta on every commit. Each adjustment fires onScroll, which can commit again, so an inverted FlatList with a header that drops to a single row scrolls away on its own.

The anchor is now cleared at the start of every prepare, so adjust only uses one picked for the current mount.

Fixes #60260

Changelog:

[IOS] [FIXED] - Fix maintainVisibleContentPosition scrolling the list away when no anchor is found at minIndexForVisible

Test Plan:

Added testMaintainVisibleContentPositionWithoutAnchorDoesNotReuseThePreviousOne to RCTScrollViewComponentViewTests. It anchors on a row, removes the header so the row moves up, then runs a second mount with only that row left. Without the fix the second mount should shift the offset again (-50 to -100). I don't have Xcode on this machine, so I haven't run the XCTest or the reproducer; both files are clang-formatted. The reporter tested the same one-line change from source and the list held still.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 24, 2026
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Nov 24, 2026
@github-actions

Copy link
Copy Markdown

Visual regression

No visual differences at 9abe84f4e57f.

android: no capture

@meta-codesync

meta-codesync Bot commented Nov 24, 2026

Copy link
Copy Markdown

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this in D134268351.


- (void)_prepareForMaintainVisibleScrollPosition
{
_firstVisibleView = nil;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're not resetting _firstVisibleViewTag and _prevFirstVisibleFrame either, should we?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left them alone because adjust bails out when _firstVisibleView is nil before it reads either one, and prepare always sets all three together. Happy to reset them too if you want it to match prepareForRecycle.

@javache javache left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review automatically exported from Phabricator review in Meta.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

iOS: FlatList with maintainVisibleContentPosition scrolls away on its own

3 participants