Skip to content

Fix ScrollView recycled content inset#57494

Open
adamivancza wants to merge 1 commit into
react:mainfrom
adamivancza:fix-scrollview-contentinset-recycle
Open

Fix ScrollView recycled content inset#57494
adamivancza wants to merge 1 commit into
react:mainfrom
adamivancza:fix-scrollview-contentinset-recycle

Conversation

@adamivancza

Copy link
Copy Markdown

Summary:

Fixes #57314.

When a Fabric ScrollView is recycled on iOS, prepareForRecycle resets native scroll state before the view is reused. contentInset was being reset to UIEdgeInsetsZero, which prevents stale native insets from leaking between recycled views, but also drops a valid non-zero contentInset from the current props.

If the recycled view is mounted again with the same contentInset prop value, updateProps may not reapply it because the props did not change. This can leave the native UIScrollView with contentInset = 0 even though React props still specify a non-zero inset.

This change keeps the stale-state protection, but resets contentInset back to the value from the current props instead of always zeroing it.

Changelog:

[IOS] [FIXED] - Preserve Fabric ScrollView contentInset when recycling iOS native views

Test Plan:

Verified with the repro from #57314:

  1. Cloned and installed gimi-anders/rn-contentinset-recycle-repro
  2. Ran the app with the existing implementation and reproduced the issue:
    • Step 0: first ScrollView reports native contentInset.top = 200
    • Step 1: first ScrollView is unmounted
    • Step 2: recycled ScrollView reports native contentInset.top = 0
  3. Applied this change to the repro app’s local React Native source and rebuilt with React Native Core built from source.
  4. Re-ran the repro:
    • Step 2 now reports native contentInset.top = 200

Also verified that the previous stale-inset protection is preserved: prepareForRecycle still overwrites the recycled native UIScrollView.contentInset; it now overwrites it with the current props value instead of always using UIEdgeInsetsZero.

Before After
https://github.com/user-attachments/assets/e69ce800-23ab-4406-8700-f57511af85d8 https://github.com/user-attachments/assets/35b93cff-0804-455c-a85c-2c0b05d35417

@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 Jul 9, 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 Jul 9, 2026
@meta-codesync

meta-codesync Bot commented Jul 9, 2026

Copy link
Copy Markdown

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

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][Fabric] Recycled ScrollView with a stable non-zero contentInset keeps the zeroed inset from prepareForRecycle

1 participant