react / react/react-native

[iOS][Fabric] Pinch-zoomed ScrollView breaks (position jumps, cannot zoom back out) after its size changes

Đang mở
#58,499 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Component: ScrollView Needs: Triage :mag: Platform: iOS
Ngôn ngữ chính
C++
Star
127k
Fork
25.3k
Merge trung bình
1 ngày 23 giờ
Pull request đã merge (30 ngày)
4

Mô tả

Description

On iOS with the new architecture, a ScrollView with maximumZoomScale > 1 gets into a broken state whenever its size changes while the user is zoomed in (device rotation, or the layout around it changing):

  1. The scrolled position jumps to a different spot.
  2. The content can no longer be zoomed all the way back out; it stays stuck against one side or corner.

The only way to recover is to zoom all the way out in the broken state and then resize again (rotate back and forth). After that it works again until the next resize while zoomed.

Cause. RCTScrollViewComponentView returns _containerView from viewForZoomingInScrollView:, so while zoomed in that view carries UIScrollView's scale transform. In updateState:oldState: a content size change does

_containerView.frame = CGRect{RCTCGPointFromPoint(data.contentBoundingRect.origin), contentSize};
...
self->_scrollView.contentSize = contentSize;
  • Setting frame on a view whose transform is not the identity is undefined behavior per the UIView docs ("If the transform property is not the identity transform, the value of this property is undefined and therefore should be ignored"). In practice UIKit shrinks the container's bounds by the zoom scale, so when the user zooms back out to scale 1 the content is smaller than the scroll view and sits in a corner.
  • contentSize is set to the unzoomed size while zoomScale != 1. UIScrollView itself keeps contentSize at the zoomed size, so the offset is clamped to the wrong range and the position jumps.

The same code is on main today. prepareForRecycle already hints at it: "Invalidate cached content size so that updateState: recalculates the container frame after zoomScale reset (which may have mutated it in RTL)".

Fix: lay the container out through bounds/center and give the scroll view the zoomed content size. PR: https://github.com/react/react-native/pull/58498

Steps to reproduce
  1. Run the reproducer on an iOS device or simulator (new architecture is on by default).
  2. Pinch to zoom in (2x or more) and pan somewhere away from the top-left.
  3. Tap "Resize" (changes the ScrollView's height) or rotate the device.
  4. The position jumps. Pinch back out: the content stays stuck in a corner and does not fill the ScrollView.
  5. Zoom out fully, resize again: it recovers.
React Native Version

0.87.1

Affected Platforms

Runtime - iOS

Output of npx @react-native-community/cli info
Not run: the reproducer repository is a fresh `reproducer-react-native` template pinned to react-native 0.87.1, run on iOS 18 simulator/device.
Stacktrace or Logs
No crash or log output; the bug is visual.
MANDATORY Reproducer

https://github.com/mifi/reproducer-react-native

Screenshots and Videos

None yet.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với updateState:oldState: và prepareForRecycle của RCTScrollViewComponentView, sau đó chạy ví dụ reproducer-react-native trên iOS. Xác minh hành vi khi đang phóng to/thu nhỏ và khi thay đổi kích thước hoặc xoay; hoàn tất khi vị trí cuộn vẫn ổn định và nội dung có thể thu nhỏ hoàn toàn trở lại sau khi kích thước thay đổi.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
ios, objective-c, react-native
Lĩnh vực
mobile
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.