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 ef50487f91200e..dda3a283939f7a 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 @@ - (TextMeasurement)_measureTextStorage:(NSTextStorage *)textStorage 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,14 @@ - (TextMeasurement)_measureTextStorage:(NSTextStorage *)textStorage 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;