Skip to content

Commit 40d7233

Browse files
authored
fix(ios): pin measured width to maxWidth for multiline content to prevent flexShrink clipping (#291)
1 parent b5402ef commit 40d7233

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

ios/utils/ENRMTextViewSetup.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,22 @@ static inline CGSize ENRMMeasureMarkdownText(ENRMPlatformTextView *textView, CGF
4343
CGFloat measuredWidth = layout.usedRect.size.width;
4444
CGFloat measuredHeight = layout.usedRect.size.height;
4545

46+
// Detect multiline content by checking if the layout produced more than one
47+
// line fragment. When text wraps, returning the tight usedRect width lets
48+
// flexShrink narrow the view below maxWidth, causing re-wrap at the narrower
49+
// width and a height mismatch. Pin to maxWidth for multiline content so Yoga
50+
// assigns the width the text was actually measured at. Single-line content
51+
// keeps its tight width for shrink-to-fit behavior.
52+
NSLayoutManager *layoutManager = textView.layoutManager;
53+
NSUInteger glyphCount = [layoutManager numberOfGlyphs];
54+
if (glyphCount > 0) {
55+
NSRange firstLineRange;
56+
[layoutManager lineFragmentRectForGlyphAtIndex:0 effectiveRange:&firstLineRange];
57+
if (NSMaxRange(firstLineRange) < glyphCount) {
58+
measuredWidth = maxWidth;
59+
}
60+
}
61+
4662
if (!CGRectIsEmpty(layout.extraLineFragmentRect)) {
4763
measuredHeight -= layout.extraLineFragmentRect.size.height;
4864
}

0 commit comments

Comments
 (0)