-
Notifications
You must be signed in to change notification settings - Fork 5.7k
fix(mobile): prevent text clipping on iOS chat messages #11614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -241,13 +241,26 @@ static void applyAttachments( | |
| [layoutManager ensureLayoutForTextContainer:textContainer]; | ||
| const CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer]; | ||
|
|
||
| // NSLayoutManager with usesFontLeading=NO can underreport height by up to | ||
| // one line's worth of leading, causing text to be clipped at the bottom of | ||
| // its container on iOS. Adding a fraction of the base line height as a | ||
| // buffer ensures the measured size always encompasses the rendered glyphs. | ||
| Float heightBuffer = 0; | ||
| if (!baseAttributedString.isEmpty()) { | ||
| const auto &firstFragment = baseAttributedString.getFragments().front(); | ||
| const Float lineHeight = firstFragment.textAttributes.lineHeight.value_or(0); | ||
| if (lineHeight > 0) { | ||
| heightBuffer = lineHeight * 0.15f; | ||
| } | ||
| } | ||
|
Comment on lines
+250
to
+255
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium A later heading can still be clipped because - if (!baseAttributedString.isEmpty()) {
- const auto &firstFragment = baseAttributedString.getFragments().front();
- const Float lineHeight = firstFragment.textAttributes.lineHeight.value_or(0);
- if (lineHeight > 0) {
- heightBuffer = lineHeight * 0.15f;
- }
- }
+ for (const auto &fragment : baseAttributedString.getFragments()) {
+ const Float lineHeight = fragment.textAttributes.lineHeight.value_or(0);
+ heightBuffer = std::max(heightBuffer, lineHeight);
+ }
+ heightBuffer *= 0.15f;🤖 Copy this AI Prompt to have your agent fix this: |
||
|
|
||
| return { | ||
| std::clamp( | ||
| static_cast<Float>(std::ceil(usedRect.size.width)), | ||
| layoutConstraints.minimumSize.width, | ||
| layoutConstraints.maximumSize.width), | ||
| std::clamp( | ||
| static_cast<Float>(std::ceil(usedRect.size.height)), | ||
| static_cast<Float>(std::ceil(usedRect.size.height + heightBuffer)), | ||
| layoutConstraints.minimumSize.height, | ||
| layoutConstraints.maximumSize.height), | ||
| }; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Derive the buffer from the largest rendered line metric.
nativeMarkdownDocumentRunscan append a body paragraph followed by a heading in one attributed string. The heading receives its own largerfontSizeandlineHeight.T3MarkdownTextShadowNode::measureContentstill adds only0.15 * firstFragment.lineHeight. ItsusesFontLeading = NOpath can underreport the rendered glyph height, andT3MarkdownTextassigns the measured frame to the clipped_textView. Derive the buffer from the relevant rendered metrics, or a proven upper bound such as the maximum positive fragment metric. Add a mixed-fragment regression test.🤖 Prompt for AI Agents