Skip to content

Commit

Permalink
set max lines to 1 if we've exhausted all lines in an attempt to fit …
Browse files Browse the repository at this point in the history
…text

Summary:
After D54698703 landed, I was looking through the screenshots and saw regressions like the below:

 {F1468068992}

The edge case here is that we keep the `linesWithinConstrainedBounds` as zero if we were never able to fit within the constraints and we've exhausted all the available lines in the layout. Setting the `linesWithinConstrainedBounds` to zero will cause the text to be drawn unbounded and overflow the constraints which is not what we want.

In this diff, we'll set the number of lines that can fit to 1 if we've exhausted all lines and were not able to fit within the constraints.

NOTE: This may still end up in the text being cut height wise if the height at 1 line still exceeds the constraints. Think of this mitigation as a last hail mary to show the ellipsis. Better to try than never

Reviewed By: rooju

Differential Revision: D54836935

fbshipit-source-id: f5dbfdc0a913c4ec80208ff0e84db5dce7167523
  • Loading branch information
Daniel Famakin authored and facebook-github-bot committed Mar 13, 2024
1 parent 01e53f1 commit 89a53b3
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ private static Pair<Rect, TextLayout> maybeFitTextToConstraints(

final int measuredHeightConstraint = initialResult.first.height();

int linesWithinConstrainedBounds = 0;
// Make sure we have the bare minimum line count if we've exhausted all lines and weren't able
// to fit. This allows to show the ellipsis in the best case scenario signaling truncation
int linesWithinConstrainedBounds = 1;
int lineIndex = layout.getLineCount() - 1;
while (lineIndex >= 0) {
if (layout.getLineBottom(lineIndex) <= measuredHeightConstraint) {
Expand Down

0 comments on commit 89a53b3

Please sign in to comment.