onTextLayout incorrectly returns multiple lines for text that renders in a single line
Chưa có ai nhận issue này.
- 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
onTextLayout is returning incorrect lines data for simple single-line text.
In previous React Native versions (tested on Expo 52 with react-native 0.79), the lines array matched the actual number of rendered lines. After the latest update (RN 0.81), some texts that clearly render in one line are reported as two lines.
This breaks logic that depends on overflow detection (e.g., switching between normal text and marquee scrolling). Because onTextLayout now gives false positives, it’s impossible to reliably detect when text exceeds one line.
Steps to reproduce
The bug is present in Expo template when created with npx create-expo-app@latest.
- Install the dependencies
npm install - Open the app in Expo Go application
- See the log in terminal. You should see the text is rendered in one line, but
onTextLayoutgives an array with 2 items.
React Native Version
0.81.5
Affected Platforms
Runtime - Android
Output of npx @react-native-community/cli info
System:
OS: macOS 26.1
CPU: (11) arm64 Apple M3 Pro
Memory: 286.83 MB / 18.00 GB
Shell:
version: 3.2.57
path: /bin/sh
Binaries:
Node:
version: 22.12.0
path: /Users/smhd/.nvm/versions/node/v22.12.0/bin/node
Yarn: Not Found
npm:
version: 10.9.0
path: /Users/smhd/.nvm/versions/node/v22.12.0/bin/npm
Watchman:
version: 2024.12.02.00
path: /opt/homebrew/bin/watchman
Managers:
CocoaPods: Not Found
SDKs:
iOS SDK:
Platforms:
- DriverKit 24.2
- iOS 18.2
- macOS 15.2
- tvOS 18.2
- visionOS 2.2
- watchOS 11.2
Android SDK: Not Found
IDEs:
Android Studio: 2025.1 AI-251.26094.121.2513.14007798
Xcode:
version: 16.2/16C5032a
path: /usr/bin/xcodebuild
Languages:
Java:
version: 17.0.14
path: /usr/bin/javac
Ruby:
version: 2.6.10
path: /usr/bin/ruby
npmPackages:
"@react-native-community/cli": Not Found
react:
installed: 19.1.0
wanted: 19.1.0
react-native:
installed: 0.81.5
wanted: 0.81.5
react-native-macos: Not Found
npmGlobalPackages:
"*react-native*": Not Found
Android:
hermesEnabled: Not found
newArchEnabled: Not found
iOS:
hermesEnabled: Not found
newArchEnabled: Not found
info React Native v0.82.1 is now available (your project is running on v0.81.5).
info Changelog: https://github.com/facebook/react-native/releases/tag/v0.82.1
info Diff: https://react-native-community.github.io/upgrade-helper/?from=0.81.5&to=0.82.1
info For more info, check out "https://reactnative.dev/docs/upgrading?os=macos".
Stacktrace or Logs
No stacktrace available. Not related in this case.
MANDATORY Reproducer
https://github.com/SMhdAsadi/onTextLayout-issue-rn81
Screenshots and Videos
This is the first page of a new Expo project in default template:
The title "Welcome!" is rendered in one line, but is reported to be in two lines in onTextLayout prop.
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Chạy reproducer bắt buộc tại https://github.com/SMhdAsadi/onTextLayout-issue-rn81 với Expo template trên Android và kiểm tra output của onTextLayout đối với văn bản một dòng “Welcome!”. Truy vết đường dẫn bố cục văn bản Android của React Native tạo ra lines array. Hoàn tất khi một văn bản được render trên một dòng báo cáo một dòng mà không làm gián đoạn việc phát hiện tràn.
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-native
- Lĩnh vực
- mobile-dev
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Ít trao đổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 55/100