react / react/react-native

【Android&IOS】Percentage calculations ignore the parent container’s padding and are based on the content box instead of the border box.

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

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

Issue: Author Provided Repro Needs: React Native Team Attention Platform: Android 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

When the parent container has horizontal padding, using
left: '50%' + transform: [{ translateX: '-50%' }]
to center an absolutely positioned element results in the element being centered relative to the content box (excluding padding), rather than the full container width.

This behavior is inconsistent with web CSS, where left: 50% is calculated relative to the border box (including padding).

Additionally, testing shows that setting width: '50%' behaves consistently with left: '50%' — the percentage value is also calculated excluding padding, meaning it uses the content box width as the reference instead of the full container width.

As a result, both position and size percentages are computed relative to the content area, not the visual box including padding.

Both iOS and Android show the same issue

Steps to reproduce
  1. clone the reproduction repo and install dependencies
  2. npm run ios or npm run android
React Native Version

0.82.1、0.77.2

Affected Platforms

Runtime - iOS, Runtime - Android

Output of npx @react-native-community/cli info
System:
  OS: macOS 14.2.1
  CPU: (8) arm64 Apple M3
  Memory: 133.56 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 23.10.0
    path: /Users/didi/.nvm/versions/node/v23.10.0/bin/node
  Yarn:
    version: 1.22.22
    path: /Users/didi/.nvm/versions/node/v23.10.0/bin/yarn
  npm:
    version: 10.9.2
    path: /Users/didi/.nvm/versions/node/v23.10.0/bin/npm
  Watchman:
    version: 2024.10.21.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: Not Found
IDEs:
  Android Studio: 2023.3 AI-233.14808.21.2331.11709847
  Xcode:
    version: 15.3/15E204a
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.11
    path: /usr/bin/javac
  Ruby:
    version: 3.1.0
    path: /Users/didi/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 20.0.0
    wanted: 20.0.0
  react:
    installed: 19.1.1
    wanted: 19.1.1
  react-native:
    installed: 0.82.1
    wanted: 0.82.1
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: Not found
  newArchEnabled: false
Stacktrace or Logs
no log
MANDATORY Reproducer

https://github.com/yandadaFreedom/RN-bug-repo/tree/bug-left-percent

Screenshots and Videos
Image

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 trình tái hiện bắt buộc tại https://github.com/yandadaFreedom/RN-bug-repo/tree/bug-left-percent và chạy npm run ios hoặc npm run android. So sánh việc định vị và định kích thước theo phần trăm khi phần tử cha có padding theo chiều ngang trên cả hai nền tảng; được xem là hoàn thành khi hành vi nhất quán với kỳ vọng border-box đã được báo cáo trên iOS và Android.

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

Đánh giá

Công nghệ
react-native
Lĩnh vực
mobile
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 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
32/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.