diff --git a/lib/java/com/google/android/material/internal/CollapsingTextHelper.java b/lib/java/com/google/android/material/internal/CollapsingTextHelper.java index bea422678d8..a84e4d69dfd 100644 --- a/lib/java/com/google/android/material/internal/CollapsingTextHelper.java +++ b/lib/java/com/google/android/material/internal/CollapsingTextHelper.java @@ -92,7 +92,6 @@ public final class CollapsingTextHelper { private final View view; - private boolean drawTitle; private float expandedFraction; private boolean fadeModeEnabled; private float fadeModeStartFraction; @@ -246,7 +245,6 @@ public void setExpandedBounds(int left, int top, int right, int bottom) { if (!rectEquals(expandedBounds, left, top, right, bottom)) { expandedBounds.set(left, top, right, bottom); boundsChanged = true; - onBoundsChanged(); } } @@ -258,7 +256,6 @@ public void setCollapsedBounds(int left, int top, int right, int bottom) { if (!rectEquals(collapsedBounds, left, top, right, bottom)) { collapsedBounds.set(left, top, right, bottom); boundsChanged = true; - onBoundsChanged(); } } @@ -268,9 +265,10 @@ public void setCollapsedBounds(@NonNull Rect bounds) { public void getCollapsedTextActualBounds(@NonNull RectF bounds, int labelWidth, int textGravity) { isRtl = calculateIsRtl(text); - bounds.left = getCollapsedTextLeftBound(labelWidth, textGravity); + bounds.left = max(getCollapsedTextLeftBound(labelWidth, textGravity), collapsedBounds.left); bounds.top = collapsedBounds.top; - bounds.right = getCollapsedTextRightBound(bounds, labelWidth, textGravity); + bounds.right = + min(getCollapsedTextRightBound(bounds, labelWidth, textGravity), collapsedBounds.right); bounds.bottom = collapsedBounds.top + getCollapsedTextHeight(); } @@ -350,14 +348,6 @@ private void getTextPaintCollapsed(@NonNull TextPaint textPaint) { } } - void onBoundsChanged() { - drawTitle = - collapsedBounds.width() > 0 - && collapsedBounds.height() > 0 - && expandedBounds.width() > 0 - && expandedBounds.height() > 0; - } - public void setExpandedTextGravity(int gravity) { if (expandedTextGravity != gravity) { expandedTextGravity = gravity; @@ -839,7 +829,7 @@ private void setExpandedTextBlend(float blend) { public void draw(@NonNull Canvas canvas) { final int saveCount = canvas.save(); // Compute where to draw textLayout for this frame - if (textToDraw != null && drawTitle) { + if (textToDraw != null && currentBounds.width() > 0 && currentBounds.height() > 0) { textPaint.setTextSize(currentTextSize); float x = currentDrawX; float y = currentDrawY; diff --git a/lib/java/com/google/android/material/textfield/TextInputLayout.java b/lib/java/com/google/android/material/textfield/TextInputLayout.java index 7d70143b3e5..a30b55551a1 100644 --- a/lib/java/com/google/android/material/textfield/TextInputLayout.java +++ b/lib/java/com/google/android/material/textfield/TextInputLayout.java @@ -3954,6 +3954,9 @@ private void openCutout() { final RectF cutoutBounds = tmpRectF; collapsingTextHelper.getCollapsedTextActualBounds( cutoutBounds, editText.getWidth(), editText.getGravity()); + if (cutoutBounds.width() <= 0 || cutoutBounds.height() <= 0) { + return; + } applyCutoutPadding(cutoutBounds); // Offset the cutout bounds by the TextInputLayout's paddings, half of the cutout height, and