react / react/react-native

Text renders 1px bigger than View when explicitly given the same height with a specific combination of height and pixel ratio.

Đang mở
#42,140 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 Type: New Architecture
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

Explicitly setting height: 15 on a parent View and child Text on a device with a pixel ratio of 3.5 (Pixel 7 Pro emulator) causes the child Text to render 1 px bigger than the parent View due to rounding in Yoga. When the Text is given a small border (borderWidth: 0.5) the bottom of the border is clipped by the parent View. This only happens with a certain offset from top - achieved for example by setting marginTop: 295.

There are several values and combinations of height and pixelRatio that give this result. I've only observed this on Fabric, on old architecture it renders the same.

Steps to reproduce
  1. Enable new architecture
  2. Use the following code:
const print_height = (layout: LayoutRectangle, component: string) => {
  const {height} = layout;
  console.log(`${component}'s height = ${height}`);
};

const TestApp = () => {
  return (
    <View
      style={styles.View}
      onLayout={event => print_height(event.nativeEvent.layout, 'View')}>
      <Text
        style={styles.Text}
        onLayout={event => print_height(event.nativeEvent.layout, 'Text')}>
        kkkkkkkk
      </Text>
    </View>
  );
};

const styles = StyleSheet.create({
  View: {
    justifyContent: 'center',
    alignItems: 'center',
    overflow: 'hidden',
    height: 15,
    marginTop: 295,
  },
  Text: {
    fontSize: 8,
    overflow: 'hidden',
    height: 15,
    borderWidth: 0.5,
    borderRadius: 4,
  },
});
  1. Run on a device/emulator with pixelRatio: 3.5 (ex. Pixel 7 Pro)
React Native Version

0.73.1

Affected Platforms

Runtime - Android

Areas

Fabric - The New Renderer

Output of npx react-native info
System:
  OS: macOS 13.5.2
  CPU: (8) arm64 Apple M1 Pro
  Memory: 100.84 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 20.8.0
    path: /opt/homebrew/bin/node
  Yarn:
    version: 1.22.21
    path: /opt/homebrew/bin/yarn
  npm:
    version: 10.1.0
    path: /opt/homebrew/bin/npm
  Watchman:
    version: 2023.09.25.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods: Not Found
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.2
      - iOS 17.2
      - macOS 14.2
      - tvOS 17.2
      - watchOS 10.2
  Android SDK: Not Found
IDEs:
  Android Studio: 2022.3 AI-223.8836.35.2231.10406996
  Xcode:
    version: 15.1/15C65
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.6
    path: /usr/bin/javac
  Ruby:
    version: 3.2.2
    path: /opt/homebrew/opt/ruby/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.73.1
    wanted: 0.73.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
n\a
Reproducer

https://github.com/zglapa/reproducer_view_text_size

Screenshots and Videos
Screenshot 2024-01-04 at 12 17 51

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

Issue không nêu tên tệp hay bài kiểm thử nào trong repository. Hãy bắt đầu bằng cách chạy reproducer được liên kết với Fabric được bật trên thiết bị hoặc trình giả lập Android sử dụng tỷ lệ pixel 3.5, sau đó theo dõi hành vi làm tròn layout trong đường dẫn Fabric/Yoga. Được xem là hoàn tất khi chiều cao vốn được chỉ rõ là bằng nhau của View và Text vẫn bằng nhau, đồng thời đường viền nửa pixel không bị cắt trong reproducer đượ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ệ
android, react
Lĩnh vực
mobile-dev
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
38/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.