Skip to content

[iOS] Ensure RCTScrollViewComponentView scroll view always matches its bounds#57521

Open
davidecallegaro wants to merge 1 commit into
react:mainfrom
davidecallegaro:fix-scrollview-matches-bounds
Open

[iOS] Ensure RCTScrollViewComponentView scroll view always matches its bounds#57521
davidecallegaro wants to merge 1 commit into
react:mainfrom
davidecallegaro:fix-scrollview-matches-bounds

Conversation

@davidecallegaro

@davidecallegaro davidecallegaro commented Jul 11, 2026

Copy link
Copy Markdown

Summary

Fixes the "ScrollView content laid out but never drawn" failure on Fabric iOS: RCTScrollViewComponentView sizes its inner RCTEnhancedScrollView only via an autoresizing mask, and the scroll view is created at CGRectZero (initWithFrame:self.bounds at component-view creation time). Autoresizing propagates deltas only at the instant the parent's frame changes — if that moment is missed (observed reliably under heavy mount/teardown churn on thermally-throttled devices), the inner scroll view remains 0×0 forever: the shell carries its correct Yoga frame, onLayout/onContentSizeChange fire normally, the content subtree is fully mounted and laid out — and everything is clipped into a zero-size viewport.

This change enforces the invariant explicitly instead of relying on autoresizing alone: _ensureScrollViewMatchesBounds re-glues the scroll view to the shell's bounds in updateLayoutMetrics: and layoutSubviews. It adjusts bounds.size + center (not frame) so the RTL scale(-1, 1) transform is respected, and preserves bounds.origin, which for UIScrollView is the contentOffset. No-op when everything is healthy.

Diagnosis evidence (native view-hierarchy capture of a live occurrence, plus a setFrame: veto-swizzle proving nothing ever writes the zero frame — the view is born at zero and the grow-delta is missed) is in the linked issue.

Fixes #57520

Changelog:[iOS] [Fixed] - Ensure ScrollView's native scroll view always matches its component view bounds (fixes permanently-invisible ScrollView content when the autoresizing delta is missed)

Test Plan

  • On-device verification (iPhone 15 Pro Max, iOS 26.5, RN 0.83.6 + this change applied): under the reproduction conditions (thermal state serious, screen whose ScrollView mounts one frame after the screen, repeated navigation) the desync still occurs and is now corrected within one layout pass — logged heals confirm the code path executes; the invisible-content state no longer reproduces (previously ~every mount).
  • Scrolled/RTL/contentOffset behavior unchanged: sizing uses bounds.size + center and preserves bounds.origin (contentOffset) and the RTL transform.
  • Existing behavior is unchanged whenever the scroll view already matches its shell (the guard makes the method a no-op).

The inner RCTEnhancedScrollView is created at CGRectZero and sized only
by its autoresizing mask. Autoresizing propagates deltas at the moment
the parent frame changes; if that moment is missed (heavy mount /
teardown churn, reproducible on thermally-throttled devices), the scroll
view stays zero-sized forever and fully-mounted, correctly-laid-out
content is clipped into invisibility while ShadowTree layout events keep
firing. Enforce the invariant explicitly in updateLayoutMetrics and
layoutSubviews, preserving contentOffset (bounds.origin) and the RTL
transform (bounds.size + center rather than frame).
@meta-cla

meta-cla Bot commented Jul 11, 2026

Copy link
Copy Markdown

Hi @davidecallegaro!

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 Jul 11, 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 Jul 11, 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 11, 2026
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] ScrollView content permanently invisible: inner RCTEnhancedScrollView left at CGRectZero when the autoresizing delta is missed

1 participant