Fix for iOS text truncation issues. (0.81.4 branch) - #21
Open
andrewkunkel wants to merge 4 commits into
Open
Conversation
Extract the duplicated RCTTruncatedAttributedStringForStroke helper out of
RCTTextView.mm and RCTTextLayoutManager.mm into a single shared unit in
React-Core (React/Base/RCTTextStroke.{h,mm}), which both the legacy
(React-RCTText) and Fabric (React-FabricComponents) text pods depend on.
Also document that the helper only supports tail truncation (the mode used
by stroke effects); clip returns the string unchanged and head/middle would
need mode-specific ellipsis placement.
Co-authored-by: Cursor <cursoragent@cursor.com>
insacc
reviewed
Jul 24, 2026
|
|
||
| #import <React/RCTTextStroke.h> | ||
|
|
||
| NSAttributedString *RCTTruncatedAttributedStringForStroke( |
There was a problem hiding this comment.
so basically we're adding one additional rendering cycle to get the truncated text and then use it, iiuc, right?
Author
There was a problem hiding this comment.
Yeah that's my understanding of it. Updated the PR though with a reduced change set that only targets Fabric.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
See #19 for the identical fix on 0.86.0. I'm sending this one out first because it's easier for me to test, since 0.86.0 isn't live yet, and I'll send out the same change to that branch afterwards. Actually releasing this to the mobile client can wait until 0.86.0 goes out.
Summary
Display names with a stroke effect (Neon, Toon, Pop) don't truncate correctly on iOS. When the name overflows, instead of showing an ellipsis the last word is silently dropped — Android truncates with "…" as intended, iOS does not. This PR makes iOS match Android.
What broke and why
Layout-impacting effects are clamped to a single line with tail truncation (lineClamp: 1, ellipsizeMode: 'tail' in
UsernameWithEffects.tsx). On iOS, stroked text is not drawn byNSLayoutManager— it's drawn by a custom two-pass Core Text renderer (stroke outline + fill) so we can produce a rounded outline of a specific width. That path exists in both the Fabric renderer (RCTTextLayoutManager.mm→drawAttributedString, the path we actually hit) and the legacy one (RCTTextView.mm→drawRect).The problem:
CTFramesetterCreateFramedoes its own line breaking and ignores theNSTextContainer's maximumNumberOfLines and truncating line-break mode. So whileNSLayoutManagercorrectly truncates the name to one line with an ellipsis, the Core Text pass is handed the full attributed string, wraps the overflowing last word onto a second line that falls outside the clamped one-line frame, and clips it away — no ellipsis, just a missing word. The non-stroke path never had this bug because it draws the glyphs NSLayoutManager already laid out and truncated.How we're fixing it
We reconstruct the exact visible, truncated text that NSLayoutManager produced and feed that to Core Text, so the stroke passes render the same content the non-stroke path would.
A shared helper
RCTTruncatedAttributedStringForStrokewalks the laid-out line fragments and rebuilds the visible string: the visible characters plus an ellipsis carrying the last visible character's attributes, with explicit newlines inserted at soft-wrap points so Core Text reproduces the same line breaks.Both the Fabric and legacy stroke-drawing paths use this helper for their stroke and fill passes, so overflowing stroked names now show a trailing "…" identical to Android and to non-stroked text.
Before (Android -> iOS)
After (Android -> iOS)