[iOS][Fabric] numberOfLines={1} with CJK text collapses to first character + ellipsis when tail truncation is required (0.86.0)
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
On iOS with the New Architecture (RN 0.86.0), <Text numberOfLines={1}> collapses to just the first character + ellipsis (e.g. 中文标题(银色示例、金色文字) → 中...) when all of the following hold:
- the string needs tail truncation (wider than the container), and
- the string contains a full-width bracket pair
(…), and - the string ends with the closing bracket
).
Line wrapping of the same string (no numberOfLines) breaks at exactly the container edge, and middle / head / clip ellipsization all work — only the tail truncation path collapses. Android renders all cases correctly.
Minimal reproducer
No flex involved — a fixed-width box is enough:
import React from 'react';
import { View, Text } from 'react-native';
const CASES = [
'中文标题(银色示例、金色文字)', // ❌ BUG: renders as 中... (first char + ellipsis)
'中文标题(银色示例、金色文字)字', // ✅ same + 1 trailing han char: truncates correctly
'一段较长的中文标题文字内容例)', // ✅ unpaired closing bracket: correct
'一段较长的中文标题文字内容示例。', // ✅ ends with full-width period: correct
'Mechanical watch gold (silver)', // ✅ ASCII closing paren: correct
];
export default function App() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<View style={{ width: 240, borderWidth: 1 }}>
{CASES.map((s, i) => (
<Text key={i} numberOfLines={1} style={{ fontSize: 17 }}>
{s}
</Text>
))}
</View>
</View>
);
}
Reproducer: Open in Expo Snack (iOS) — same code as above, loaded via the Snack code URL parameter.
Evidence / trigger characterization
Measured on device via onTextLayout (lines[0].width, container 240pt, fontSize 17):
| String | Shape | lines[0].width | Result |
|---|---|---|---|
中文标题(银色示例、金色文字) |
bracket pair, ends with ) |
34 | ❌ collapses to 中... |
中文标题(银色示例、金色文字)字 |
same + trailing han char | 231 | ✅ |
一段较长的中文标题文字内容例) |
) at end, no opening ( |
236 | ✅ |
一段较长的中文标题文字内容示例。 |
ends with 。 |
236 | ✅ |
Mechanical watch gold (silver) |
ASCII ) at end |
231 | ✅ |
一段较长的中文标题文字内容示例 |
pure han, slight overflow | 236 | ✅ |
| long CJK strings overflowing by a lot (with or without brackets mid-string) | — | ~236 | ✅ |
Further observations for the failing case:
onTextLayoutreports a single line whosetextis the full string but whosewidthis ≈ 34pt (first glyph + ellipsis), whileonLayoutof the<Text>reports the correct frame width (240pt).- Without
numberOfLines, the same string wraps at exactly the container edge — line breaking is correct; only tail truncation collapses. ellipsizeMode="middle" | "head" | "clip"all render correctly for the same string.- Independent of font weight, explicit
lineHeight,lineBreakStrategyIOS(none/standard), and layout context (fixed-width box, flex column, flex row all reproduce identically). - Android (same JS) renders all cases correctly.
Expected behavior
Fills the available width before ellipsizing, e.g. 中文标题(银色示例、金色... — as Android does.
Actual behavior
Renders 中... (first character + ellipsis) with the rest of the 240pt frame empty.
Workaround
Platform-gate the ellipsize mode for potentially-CJK single-line text: ellipsizeMode={Platform.OS === "ios" ? "middle" : "tail"}.
Version / environment
- react-native 0.86.0 (New Architecture / Fabric), Hermes
- Reproduces: physical iPhone on iOS 26.5.2 — both in an Expo SDK 57 development client (RN 0.86.0) and in Expo Go (SDK 57) opening the Snack above
- Does NOT reproduce: the same Snack in Snack's embedded iOS simulator — but note that the embedded simulator only offers SDK 54 (RN 0.81.x) (SDK 55 is listed but errors out), so this contrast varies both the RN version and the OS version and cannot isolate which one matters
- Interpretation: the non-repro on the SDK 54 simulator is consistent with a regression introduced somewhere in RN 0.82–0.86 (e.g. the truncation-pipeline changes), but an iOS 26.x TextKit behavior change cannot be excluded either — we have no second iOS device/OS to separate the two
- Android with the same JS is unaffected
Possibly related
- #57499 (NSRangeException in
processTruncatedAttributedText— same truncation pipeline) - #57501 (clipping of last-line orphan token without
numberOfLines— possibly the same backtracking logic)
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
Bắt đầu bằng cách tái hiện trường hợp dấu ngoặc CJK trên thiết bị iOS vật lý với RN 0.86.0, sau đó kiểm tra đường dẫn cắt ngắn ở phần cuối của Fabric, bao gồm processTruncatedAttributedText và các issue liên quan #57499 và #57501. Được xem là hoàn tất khi chuỗi bị lỗi lấp đầy chiều rộng khả dụng trước khi áp dụng dấu ba chấm ở cuối, trong khi các trường hợp đối chứng được liệt kê vẫn chính xác.
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, 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
- Sôi nổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 52/100