Skip to content

[iOS] recycled ScrollView is incorrectly offset to the left of the window when in RTL #55768

@kligarski

Description

@kligarski

Description

When working on RTL support in react-native-screens, we noticed a bug with ScrollView disappearing after navigation action. When we checked the view hierarchy, it turned out that the ScrollView's content moves outside the window, to the left of the screen, by its width. If you repeat the same navigation action multiple times, the ScrollView's content is offset to the left by some multiple of its width.

  1. The bug happens only in RTL (e.g. when forceRTL(true) is used)
  2. When you disable recycling for RCTScrollViewComponentView, the bug does not happen.
  3. After some debugging, we managed to find the exact change responsible for this bug: b37023c. When you remove this line, the bug does not happen.
  4. It seems like UIKit changes layer position when zoomScale is changed:
Image

This results in _containerView.frame being changed. When RCTScrollViewComponentView is used again, _containerView.frame is not updated in updateState:oldState: due to an early return:

  CGSize contentSize = RCTCGSizeFromSize(data.getContentSize());

  NSLog(@"[RCTScrollViewComponentView_debug] updateState _contentSize %@ vs contentSize %@", NSStringFromCGSize(_contentSize), NSStringFromCGSize(contentSize));
  if (CGSizeEqualToSize(_contentSize, contentSize)) {
    NSLog(@"[RCTScrollViewComponentView_debug] updateState early return, _containerView.frame %@", NSStringFromCGRect(_containerView.frame));
    return;
  }

  _contentSize = contentSize;
  NSLog(@"[RCTScrollViewComponentView_debug] updateState updating _containerView.frame before: %@", NSStringFromCGRect(_containerView.frame));
  _containerView.frame = CGRect{RCTCGPointFromPoint(data.contentBoundingRect.origin), contentSize};
  NSLog(@"[RCTScrollViewComponentView_debug] updateState updating _containerView.frame after: %@", NSStringFromCGRect(_containerView.frame));
[RCTScrollViewComponentView_debug] updateState _contentSize {0, 0} vs contentSize {402, 919}
[RCTScrollViewComponentView_debug] updateState updating _containerView.frame before: {{0, 0}, {0, 0}}
[RCTScrollViewComponentView_debug] _containerView.layer.position changed from {0, 0} to {201, 459.5}
[RCTScrollViewComponentView_debug] updateState updating _containerView.frame after: {{0, 0}, {402, 919}}

=== frame change happens here: ===

[RCTScrollViewComponentView_debug] prepareForRecycle reseting zoom scale, _containerView.frame {{0, 0}, {402, 919}}
[RCTScrollViewComponentView_debug] _containerView.layer.position changed from {201, 459.5} to {603, 1378.5}
[RCTScrollViewComponentView_debug] _containerView.layer.position changed from {603, 1378.5} to {603, 459.5}
[RCTScrollViewComponentView_debug] prepareForRecycle finished reseting zoom scale, _containerView.frame {{402, 0}, {402, 919}}

=== ScrollView is recycled but updateState does not update the frame: ===

[RCTScrollViewComponentView_debug] updateState _contentSize {402, 919} vs contentSize {402, 919}
[RCTScrollViewComponentView_debug] updateState early return, _containerView.frame {{402, 0}, {402, 919}}
  1. Resetting _contentSize to CGSizeZero in prepareForRecycle: after changing _scrollView.zoomScale fixes the bug but I'm not sure if this is a valid fix.

Steps to reproduce

  1. Launch reproducer app on iOS simulator via Xcode.
  2. Click Push button to push a screen.
  3. Verify that ScrollView is visible.
  4. Click Pop button.
  5. Click Push button once again.
  6. ScrollView will not be visible. Check View Hierarchy in Xcode with Show Clipped Content enabled to verify that ScrollView's content is offset to the left of the window.
  7. If you keep repeating pop-push operations and check View Hierarchy, ScrollView's content will be even further from the window.

React Native Version

0.84.0

Affected Platforms

Runtime - iOS

Output of npx @react-native-community/cli info

System:
  OS: macOS 26.3
  CPU: (12) arm64 Apple M2 Pro
  Memory: 158.81 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 24.10.0
    path: /Users/krzysztof/.nvm/versions/node/v24.10.0/bin/node
  Yarn:
    version: 1.22.22
    path: /opt/homebrew/bin/yarn
  npm:
    version: 11.6.1
    path: /Users/krzysztof/.nvm/versions/node/v24.10.0/bin/npm
  Watchman: Not Found
Managers:
  CocoaPods:
    version: 1.16.2
    path: /Users/krzysztof/.rbenv/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 25.2
      - iOS 26.2
      - macOS 26.2
      - tvOS 26.2
      - visionOS 26.2
      - watchOS 26.2
  Android SDK:
    System Images:
      - android-35 | AOSP ATD ARM 64
      - android-35 | ARM 64 v8a
    Android NDK: Not Found
IDEs:
  Android Studio: 2025.2 AI-252.25557.131.2521.14432022
  Xcode:
    version: 26.2/17C52
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.14
    path: /usr/bin/javac
  Ruby:
    version: 3.4.2
    path: /Users/krzysztof/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 20.1.0
    wanted: 20.1.0
  react:
    installed: 19.2.3
    wanted: 19.2.3
  react-native:
    installed: 0.84.0
    wanted: 0.84.0
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: true
  newArchEnabled: true

Stacktrace or Logs

In reproducer repo, I added `RCTScrollViewComponentView_withLogs.mm` with custom logs. If you install pods with `RCT_USE_PREBUILT_RNCORE=0` and replace `RCTScrollViewComponentView.mm`, you will get:

[RCTScrollViewComponentView_debug] updateState _contentSize {0, 0} vs contentSize {402, 919}
[RCTScrollViewComponentView_debug] updateState updating _containerView.frame before: {{0, 0}, {0, 0}}
[RCTScrollViewComponentView_debug] _containerView.layer.position changed from {0, 0} to {201, 459.5}
[RCTScrollViewComponentView_debug] updateState updating _containerView.frame after: {{0, 0}, {402, 919}}

=== frame change happens here: ===

[RCTScrollViewComponentView_debug] prepareForRecycle reseting zoom scale, _containerView.frame {{0, 0}, {402, 919}}
[RCTScrollViewComponentView_debug] _containerView.layer.position changed from {201, 459.5} to {603, 1378.5}
[RCTScrollViewComponentView_debug] _containerView.layer.position changed from {603, 1378.5} to {603, 459.5}
[RCTScrollViewComponentView_debug] prepareForRecycle finished reseting zoom scale, _containerView.frame {{402, 0}, {402, 919}}

=== ScrollView is recycled but updateState does not update the frame: ===

[RCTScrollViewComponentView_debug] updateState _contentSize {402, 919} vs contentSize {402, 919}
[RCTScrollViewComponentView_debug] updateState early return, _containerView.frame {{402, 0}, {402, 919}}

MANDATORY Reproducer

https://github.com/kligarski/rn-disappearing-scroll-view-rtl-reproducer

Screenshots and Videos

rtl_scroll_view_bug_1080p_trimmed.mov

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions