[go: nahoru, domu]

Fix didExceedMaxLines test fails on API 21

This bug reproduce in a corner case:
1. when ellipsis width is very small and only allow 1 char to be displayed.
2. ellipsis is turned on.
StaticLayout may not apply ellipsis because that will remove all content.
To fix the issue, we no longer assume that StaticLayout will always ellipsize exceeding text when ellipsis is turned on.

Bug: 170425011
Test: ./gradlew compose:ui:ui-text:connectedAndroidTest
Change-Id: Iaf3f13178bd70d85eb67e666ea860017cfba5219
diff --git a/text/text/src/main/java/androidx/compose/ui/text/android/TextLayout.kt b/text/text/src/main/java/androidx/compose/ui/text/android/TextLayout.kt
index b84f9f9..77edef6 100644
--- a/text/text/src/main/java/androidx/compose/ui/text/android/TextLayout.kt
+++ b/text/text/src/main/java/androidx/compose/ui/text/android/TextLayout.kt
@@ -202,11 +202,16 @@
             if (lineCount < maxLines) {
                 false
             } else {
-                if (ellipsize != null) {
-                    layout.getEllipsisCount(lineCount - 1) > 0
-                } else {
+                /* When maxLines exceeds
+                  1. if ellipsis is applied, ellipsisCount of lastLine is greater than 0.
+                  2. if ellipsis is not applies, lineEnd of the last line is unequals to
+                  charSequence.length.
+                  On certain cases, even though ellipsize is set, text overflow might still be
+                  handled by truncating.
+                  So we have to check both cases, no matter what ellipsis parameter is passed.
+                 */
+                layout.getEllipsisCount(lineCount - 1) > 0 ||
                     layout.getLineEnd(lineCount - 1) != charSequence.length
-                }
             }
     }