Skip to content

Commit a29c93a

Browse files
dsn5ftymarian
authored andcommitted
[CollapsingToolbarLayout] Fixed multiline animation for fade title collapse mode
PiperOrigin-RevId: 367285477 (cherry picked from commit 5a35bf7)
1 parent 7ffa571 commit a29c93a

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

lib/java/com/google/android/material/internal/CollapsingTextHelper.java

+19-16
Original file line numberDiff line numberDiff line change
@@ -788,8 +788,9 @@ public void draw(@NonNull Canvas canvas) {
788788
return;
789789
}
790790

791-
if (shouldDrawMultiline()) {
792-
drawMultinlineTransition(canvas, currentExpandedX, y);
791+
if (shouldDrawMultiline()
792+
&& (!fadeModeEnabled || expandedFraction > fadeModeThresholdFraction)) {
793+
drawMultilineTransition(canvas, currentExpandedX, y);
793794
} else {
794795
canvas.translate(x, y);
795796
textLayout.draw(canvas);
@@ -803,7 +804,7 @@ private boolean shouldDrawMultiline() {
803804
return maxLines > 1 && (!isRtl || fadeModeEnabled) && !useTexture;
804805
}
805806

806-
private void drawMultinlineTransition(@NonNull Canvas canvas, float currentExpandedX, float y) {
807+
private void drawMultilineTransition(@NonNull Canvas canvas, float currentExpandedX, float y) {
807808
int originalAlpha = textPaint.getAlpha();
808809
// positon expanded text appropriately
809810
canvas.translate(currentExpandedX, y);
@@ -821,20 +822,22 @@ private void drawMultinlineTransition(@NonNull Canvas canvas, float currentExpan
821822
/* x = */ 0,
822823
lineBaseline,
823824
textPaint);
824-
// Remove ellipsis for Cross-section animation
825-
String tmp = textToDrawCollapsed.toString().trim();
826-
if (tmp.endsWith(ELLIPSIS_NORMAL)) {
827-
tmp = tmp.substring(0, tmp.length() - 1);
825+
if (!fadeModeEnabled) {
826+
// Remove ellipsis for Cross-section animation
827+
String tmp = textToDrawCollapsed.toString().trim();
828+
if (tmp.endsWith(ELLIPSIS_NORMAL)) {
829+
tmp = tmp.substring(0, tmp.length() - 1);
830+
}
831+
// Cross-section between both texts (should stay at original alpha)
832+
textPaint.setAlpha(originalAlpha);
833+
canvas.drawText(
834+
tmp,
835+
/* start = */ 0,
836+
min(textLayout.getLineEnd(0), tmp.length()),
837+
/* x = */ 0,
838+
lineBaseline,
839+
textPaint);
828840
}
829-
// Cross-section between both texts (should stay at original alpha)
830-
textPaint.setAlpha(originalAlpha);
831-
canvas.drawText(
832-
tmp,
833-
/* start = */ 0,
834-
min(textLayout.getLineEnd(0), tmp.length()),
835-
/* x = */ 0,
836-
lineBaseline,
837-
textPaint);
838841
}
839842

840843
private boolean calculateIsRtl(@NonNull CharSequence text) {

0 commit comments

Comments
 (0)