Repository navigation
Avoid re-laying out truncated iOS Text on every draw - #59215
Open
hryhoriiK97 wants to merge 2 commits into
Open
hryhoriiK97 wants to merge 2 commits into
hryhoriiK97 wants to merge 2 commits into
Conversation
processTruncatedAttributedText removed and re-added the color attributes of the truncated range on every measure and draw. The edit discards the layout TextKit just computed, so the paragraph was laid out again before drawing, even when the range already had the right colors. Skip the edit when the whole range already carries the attribute of the preceding character. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Summary:
-[RCTTextLayoutManager processTruncatedAttributedText:textContainer:layoutManager:](ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTTextLayoutManager.mm) runs on every measure and every draw of a<Text>withnumberOfLines. When the last line is truncated, it gives the ellipsis the colors of the character before it.Current behavior. For the truncated range it removes and re-adds
NSForegroundColorAttributeNameandNSBackgroundColorAttributeNameunconditionally. Editing the text storage discards the layout TextKit just computed, so insidedrawAttributedString:the paragraph is laid out a second time before its glyphs are drawn. In the common case the range already carries those colors (any single-color<Text numberOfLines={...}>), so the edit changes nothing but still costs a full layout.With this change. Before editing, it checks with one
longestEffectiveRangelookup whether the whole truncated range already carries the attribute of the preceding character, and leaves the storage untouched when it does. A truncated range with other colors is recolored as before.Changelog:
[IOS] [CHANGED] - Truncated Text no longer lays out again on every draw when its ellipsis already has the right color
Test Plan:
node scripts/clang-format.js --checkon the changed file passes.xcodebuildin Release and run on a physical iPhone 15 Pro (iOS 26.6.1).-[RCTParagraphTextView drawRect:], and the time from the end of a mount to the CoreAnimation commit, which contains the drawing. iPhone 15 Pro, Release:🤖 Generated with Claude Code