Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -642,15 +642,16 @@ - (TextMeasurement)_measureTextStorage:(NSTextStorage *)textStorage
CGSize attachmentSize = attachment.bounds.size;
CGRect glyphRect = [layoutManager boundingRectForGlyphRange:range inTextContainer:textContainer];

CGRect frame;
UIFont *font = [[textStorage attributedSubstringFromRange:range] attribute:NSFontAttributeName
atIndex:0
effectiveRange:nil];
frame = {
.origin =
{glyphRect.origin.x,
glyphRect.origin.y + glyphRect.size.height - attachmentSize.height + font.descender},
.size = attachmentSize};
// Sit the attachment on the baseline TextKit laid its line out with. That accounts for the offset
// that centers glyphs within a custom `lineHeight`, and for the line's largest font. The
// attachment's own run has no font (TextKit fills in 12pt Helvetica), so its descender can't be used.
NSUInteger glyphIndex = attachmentGlyphRange.location;
CGRect lineFragmentRect = [layoutManager lineFragmentRectForGlyphAtIndex:glyphIndex
effectiveRange:NULL];
CGFloat baseline = lineFragmentRect.origin.y + [layoutManager locationForGlyphAtIndex:glyphIndex].y;

CGRect frame = {
.origin = {glyphRect.origin.x, baseline - attachmentSize.height}, .size = attachmentSize};

auto rect = facebook::react::Rect{
.origin = facebook::react::Point{.x = frame.origin.x, .y = frame.origin.y},
Expand Down
Loading