Skip to content

Commit e50fbde

Browse files
author
farfromrefuge
committed
fix(android): prevent crash with staticlayout
1 parent 61c6db2 commit e50fbde

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

packages/ui-canvas/platforms/android/java/com/akylas/canvas/StaticLayout.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,13 @@ public static android.text.StaticLayout createEllipsizeStaticLayout(android.text
6363
int i = 0;
6464
float lineHeight = staticLayout.getLineBottom(i) - staticLayout.getLineTop(i);
6565
float totalHeight = lineHeight * lineCount;
66-
67-
while (totalHeight > maxHeight && maxLines > 0) {
68-
maxLines--;
69-
i++;
70-
lineHeight = staticLayout.getLineBottom(i) - staticLayout.getLineTop(i);
71-
totalHeight = lineHeight * maxLines;
66+
if (maxLines > 1) {
67+
while (totalHeight > maxHeight && maxLines > 0) {
68+
maxLines--;
69+
i++;
70+
lineHeight = staticLayout.getLineBottom(i) - staticLayout.getLineTop(i);
71+
totalHeight = lineHeight * maxLines;
72+
}
7273
}
7374
// Check if truncation is needed
7475
if (maxLines < lineCount) {

0 commit comments

Comments
 (0)