From a03536398b4cbf109e04541ba95e63b0f37deb83 Mon Sep 17 00:00:00 2001 From: delekta Date: Wed, 11 Feb 2026 15:42:21 -0800 Subject: [PATCH] Fix: [iOS][Fabric] Correctly mark inline attachments as clipped when in truncated text range (#55518) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: ### Title [iOS] Inline attachments in truncated Text still visible (Fabric) --- ### Description On iOS with the New Architecture (Fabric), inline attachments in a `` that lie beyond the `numberOfLines` limit are still being rendered instead of being clipped. As a result, the attachment that should be clipped appears just above its wrapper. See screenshots below. --- ### MANDATORY Reproducer https://snack.expo.dev/kamildelekta/truncatedtextattachmentvisiblebug --- ### Screenshots of issue Only `maxLines` changes between these two screenshots. You can check it yourself in the expo snack above. | Text | Truncated Text | | --------- | ------- | |maxLines4 | maxLines3 | ### React Native Version ``` "react-native": "0.83.0" ``` --- ### Affected Platforms only IOS New Arch --- Pull Request resolved: https://github.com/facebook/react-native/pull/55518 Test Plan: **Visible cases** Tested multiple layouts where the attachment is in range; the attachment is shown and laid out correctly. **Clipped cases** Tested both clipping paths: (1) attachment after the last visible line → `isOutsideVisibleRange`; (2) attachment in the truncated "..." range → `isInTruncatedRange`. In both cases the attachment is correctly clipped. **Context** Before this change we only had `isInTruncatedRange`. Handling for `isOutsideVisibleRange` was added. The example below shows that these two clipping cases are mutually exclusive; in the app, both cases correctly clip the attachments. Testing code: ``` Correctly clipped {/* Case 1: isOutsideVisibleRange: 1, isInTruncatedRange: 0 */} Line 1{'\n'}Line 2{'\n'}Line 3{'\n'} {/* Case 2: isOutsideVisibleRange: 0, isInTruncatedRange: 1 */} Long text that truncates with ellipsis Visible First char text after attachment Middle of line Line 1{'\n'}Line 2 with {'\n'}Line 3 End of line 1 Line 1 {'\n'}Line 2{'\n'}Line 3 Short text, end Short text Only attachment on line {'\n'}Second line ``` and here some examples: | oldArch | newArch | newArch fixed | --------- | ------- | ------- | |oldArch | newArch | newArchFixed| --- ## Changelog: [iOS] [Fixed] - Inline attachments after the last visible line in truncated text are now correctly marked as clipped. --- ### Output of `npx react-native-community/cli info` ``` System: OS: macOS 26.2 CPU: (12) arm64 Apple M4 Pro Memory: 982.39 MB / 48.00 GB Shell: version: "5.9" path: /bin/zsh Binaries: Node: version: 22.14.0 path: /nix/store/04fc23dsflkxl4s9p6lkigia1hq3vjp2-nodejs-22.14.0/bin/node Yarn: version: 1.22.19 path: /Users/kamil/.nix-profile/bin/yarn npm: version: 10.9.2 path: /nix/store/04fc23dsflkxl4s9p6lkigia1hq3vjp2-nodejs-22.14.0/bin/npm Watchman: version: 2024.03.11.00 path: /Users/kamil/.nix-profile/bin/watchman Managers: CocoaPods: version: 1.15.2 path: /Users/kamil/.nix-profile/bin/pod SDKs: iOS SDK: Platforms: - DriverKit 25.2 - iOS 26.2 - macOS 26.2 - tvOS 26.2 - visionOS 26.2 - watchOS 26.2 Android SDK: Not Found IDEs: Android Studio: Not Found Xcode: version: 26.2/17C52 path: /usr/bin/xcodebuild Languages: Java: Not Found Ruby: version: 2.6.10 path: /usr/bin/ruby npmPackages: "react-native-community/cli": installed: 20.0.0 wanted: 20.0.0 react: installed: 19.2.0 wanted: 19.2.0 react-native: installed: 0.83.0 wanted: 0.83.0 react-native-macos: Not Found npmGlobalPackages: "*react-native*": Not Found Android: hermesEnabled: true newArchEnabled: true iOS: hermesEnabled: true newArchEnabled: true info React Native v0.83.2 is now available (your project is running on v0.83.0). ``` --- Reviewed By: NickGerleman Differential Revision: D92991293 Pulled By: CalixTang fbshipit-source-id: ebd097c4311a18e0f628fe5dd3eec353582ce423 --- .../textlayoutmanager/RCTTextLayoutManager.mm | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTTextLayoutManager.mm b/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTTextLayoutManager.mm index ef50487f912..51d9deea609 100644 --- a/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTTextLayoutManager.mm +++ b/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTTextLayoutManager.mm @@ -391,6 +391,8 @@ static NSLineBreakMode RCTNSLineBreakModeFromEllipsizeMode(EllipsizeMode ellipsi size = (CGSize){ceil(size.width * layoutContext.pointScaleFactor) / layoutContext.pointScaleFactor, ceil(size.height * layoutContext.pointScaleFactor) / layoutContext.pointScaleFactor}; + NSRange visibleGlyphRange = [layoutManager glyphRangeForTextContainer:textContainer]; + __block auto attachments = TextMeasurement::Attachments{}; [textStorage @@ -406,7 +408,15 @@ static NSLineBreakMode RCTNSLineBreakModeFromEllipsizeMode(EllipsizeMode ellipsi actualCharacterRange:NULL]; NSRange truncatedRange = [layoutManager truncatedGlyphRangeInLineFragmentForGlyphAtIndex:attachmentGlyphRange.location]; - if (truncatedRange.location != NSNotFound && attachmentGlyphRange.location >= truncatedRange.location) { + + // Attachment on a line that did not fit (e.g. on the 4th line when the container is limited to 3 lines) + BOOL isOutsideVisibleRange = !NSLocationInRange(attachmentGlyphRange.location, visibleGlyphRange); + // Attachment in the ellipsis range of the last visible line (line truncated with "..." and the + // attachment falls in that portion) + BOOL isInTruncatedRange = + truncatedRange.location != NSNotFound && attachmentGlyphRange.location >= truncatedRange.location; + + if (isOutsideVisibleRange || isInTruncatedRange) { attachments.push_back(TextMeasurement::Attachment{.isClipped = true}); } else { CGSize attachmentSize = attachment.bounds.size;