react / react/react-native

ScrollView snapToInterval/snapToOffsets not working when the scrollView width is a float number in IOS.

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

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

Component: ScrollView Issue: Author Provided Repro 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

ScrollView snapToInterval/snapToOffsets not working when the scrollView width is a float number in IOS, because isHorizontal method in RCTEnhancedScrollView return a unexpected result when the width is a float.

- (BOOL)isHorizontal:(UIScrollView *)scrollView
{
  return scrollView.contentSize.width > self.frame.size.width;
}

In my reproducer: https://snack.expo.dev/@hiyuki/scrollview-snaptointerval-bug, when i set scrollView's width with a integer, such as 100, snapToInterval/snapToOffsets works fine, but when i set the width with a float number, such as 100.3, snapToInterval/snapToOffsets does't work.

Steps to reproduce
  1. open the reproducer link: https://snack.expo.dev/@hiyuki/scrollview-snaptointerval-bug
  2. execute it with expo go in a IOS device
  3. scroll the scrollView content vertically, snapToInterval/snapToOffsets does't work when touch up
React Native Version

0.76.5

Affected Platforms

Runtime - iOS

Output of npx react-native info
System:
  OS: macOS 14.3.1
  CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
  Memory: 1.77 GB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.17.1
    path: /usr/local/bin/node
  Yarn: Not Found
  npm:
    version: 9.8.1
    path: /usr/local/bin/npm
  Watchman:
    version: 2024.01.22.00
    path: /usr/local/bin/watchman
Managers:
  CocoaPods:
    version: 1.15.2
    path: /usr/local/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.4
      - iOS 17.4
      - macOS 14.4
      - tvOS 17.4
      - visionOS 1.1
      - watchOS 10.4
  Android SDK:
    API Levels:
      - "34"
      - "35"
    Build Tools:
      - 33.0.1
      - 34.0.0
      - 35.0.0
    System Images:
      - android-34 | Intel x86_64 Atom
      - android-34 | Google APIs Intel x86_64 Atom
    Android NDK: Not Found
IDEs:
  Android Studio: 2024.1 AI-241.18034.62.2412.12266719
  Xcode:
    version: 15.3/15E204a
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.12
    path: /usr/bin/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 15.0.0-alpha.2
    wanted: 15.0.0-alpha.2
  react:
    installed: 18.3.1
    wanted: 18.3.1
  react-native:
    installed: 0.76.5
    wanted: ^0.76.5
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: true
  newArchEnabled: true
Stacktrace or Logs
no crash
Reproducer

https://snack.expo.dev/@hiyuki/scrollview-snaptointerval-bug

Screenshots and Videos

set ScrollView's width with 100.3, snapToInterval/snapToOffsets does't work.

https://github.com/user-attachments/assets/23b5d09f-a45a-4a6b-8327-1feba66bc41f

set ScrollView's width with 100, snapToInterval/snapToOffsets works fine.

https://github.com/user-attachments/assets/e72e4934-46f2-4601-b5ec-01c800ee7f3a

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 từ phương thức RCTEnhancedScrollView's isHorizontal: và tái hiện vấn đề bằng Snack được liên kết với các chiều rộng ScrollView là số nguyên và số thực dấu phẩy động trên iOS. Xác minh rằng snapToInterval và snapToOffsets snap chính xác với các chiều rộng phân số, đồng thời kiểm tra hành vi iOS liên quan đối chiếu với thiết lập React Native 0.76.5 đã được báo cáo.

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
Khá rõ ràng
Mức phù hợp với người mới
45/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.