Skip to content
Merged
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 @@ -39,6 +39,18 @@ static NSLineBreakMode RCTNSLineBreakModeFromEllipsizeMode(EllipsizeMode ellipsi
}
}

// Text is laid out with an unbounded height, as during measurement, so that lines and attachments end up where
// measurement placed them. A container clamped to the frame height makes TextKit squeeze the remaining content into
// the last line that fits. The paragraph view clips the drawing to its bounds.
static CGSize RCTTextLayoutSizeForFrameSize(CGSize frameSize, const ParagraphAttributes &paragraphAttributes)
{
if (paragraphAttributes.adjustsFontSizeToFit) {
// Font scaling shrinks the text until it fits the frame height.
return frameSize;
}
return CGSize{frameSize.width, CGFLOAT_MAX};
}

- (TextMeasurement)measureNSAttributedString:(NSAttributedString *)attributedString
paragraphAttributes:(ParagraphAttributes)paragraphAttributes
layoutContext:(TextLayoutContext)layoutContext
Expand Down Expand Up @@ -136,7 +148,7 @@ - (void)drawAttributedString:(const AttributedString &)attributedString
NSTextStorage *textStorage = [self
_textStorageAndLayoutManagerWithAttributesString:[self _nsAttributedStringFromAttributedString:attributedString]
paragraphAttributes:paragraphAttributes
size:frame.size];
size:RCTTextLayoutSizeForFrameSize(frame.size, paragraphAttributes)];
NSLayoutManager *layoutManager = textStorage.layoutManagers.firstObject;
NSTextContainer *textContainer = layoutManager.textContainers.firstObject;

Expand Down Expand Up @@ -475,7 +487,7 @@ - (NSTextStorage *)_textStorageAndLayoutManagerWithAttributesString:(NSAttribute
NSTextStorage *textStorage = [self
_textStorageAndLayoutManagerWithAttributesString:[self _nsAttributedStringFromAttributedString:attributedString]
paragraphAttributes:paragraphAttributes
size:frame.size];
size:RCTTextLayoutSizeForFrameSize(frame.size, paragraphAttributes)];
NSLayoutManager *layoutManager = textStorage.layoutManagers.firstObject;
NSTextContainer *textContainer = layoutManager.textContainers.firstObject;

Expand Down Expand Up @@ -506,7 +518,7 @@ - (void)getRectWithAttributedString:(const AttributedString &)attributedString
NSTextStorage *textStorage = [self
_textStorageAndLayoutManagerWithAttributesString:[self _nsAttributedStringFromAttributedString:attributedString]
paragraphAttributes:paragraphAttributes
size:frame.size];
size:RCTTextLayoutSizeForFrameSize(frame.size, paragraphAttributes)];

NSLayoutManager *layoutManager = textStorage.layoutManagers.firstObject;
NSTextContainer *textContainer = layoutManager.textContainers.firstObject;
Expand Down
Loading