Skip to content

Fix maintainVisibleContentPosition when ScrollView content shrinks - #58695

Open
aryan1306 wants to merge 2 commits into
react:mainfrom
aryan1306:fix/mvcp-shrink-anchor-offset
Open

aryan1306 wants to merge 2 commits into
react:mainfrom
aryan1306:fix/mvcp-shrink-anchor-offset

Conversation

@aryan1306

Copy link
Copy Markdown

Summary:

Fixes #58578.

When ScrollView content shrinks, layout can clamp the current scroll offset before maintainVisibleContentPosition adjusts the visible anchor. Applying the anchor delta to that clamped offset can move the list to the top.

Capture the scroll offset before mounting and use it when applying the anchor adjustment in Android and iOS Fabric. Add regression tests for vertical and horizontal shrinking content.

Changelog:

[GENERAL] [FIXED] - Preserve the visible ScrollView anchor when content shrinks.

Test Plan:

  • Reproduced the jump with the linked Expo app on an Android emulator: the visible child moved from anchor 49 to child 0 after collapse.
  • Ran ./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest --tests com.facebook.react.views.scroll.MaintainVisibleScrollPositionHelperTest --no-daemon: all three tests passed.
  • Ran the RNTesterUnitTests scheme on an iPhone 17 Pro simulator: all three tests in RCTScrollViewComponentViewTests passed, including the vertical and horizontal shrink regressions.
  • Confirmed the vertical iOS regression test fails against the pre-fix code: expected offset 300, received -500.

@meta-cla

meta-cla Bot commented Sep 27, 2026

Copy link
Copy Markdown

Hi @aryan1306!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@meta-cla

meta-cla Bot commented Sep 27, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@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 Sep 27, 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 Sep 27, 2026

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.

ScrollView maintainVisibleContentPosition applies the anchor delta to the already-clamped offset when content shrinks (iOS + Android, Fabric)

1 participant