Skip to content

Commit

Permalink
[TextInputLayout] Fixed cutout padding so text field outline doesn't …
Browse files Browse the repository at this point in the history
…overlap collapsed hint.

Resolves #2127

PiperOrigin-RevId: 372563674
(cherry picked from commit 87b50c6)
  • Loading branch information
leticiarossi authored and ymarian committed May 7, 2021
1 parent cee29e9 commit 982f74d
Showing 1 changed file with 8 additions and 7 deletions.
Expand Up @@ -236,7 +236,7 @@ public class TextInputLayout extends LinearLayout {
@NonNull private ShapeAppearanceModel shapeAppearanceModel;

private final int boxLabelCutoutPaddingPx;
private int boxLabelCutoutWidth;
private int boxLabelCutoutHeight;
@BoxBackgroundMode private int boxBackgroundMode;
private int boxCollapsedPaddingTopPx;
private int boxStrokeWidthPx;
Expand Down Expand Up @@ -4077,18 +4077,19 @@ private void openCutout() {
final RectF cutoutBounds = tmpRectF;
collapsingTextHelper.getCollapsedTextActualBounds(
cutoutBounds, editText.getWidth(), editText.getGravity());
boxLabelCutoutWidth = boxStrokeWidthPx;
cutoutBounds.bottom = cutoutBounds.top + boxLabelCutoutWidth;
applyCutoutPadding(cutoutBounds);
// Offset the cutout bounds by the TextInputLayout's left and top paddings to ensure that the
// cutout is inset relative to the TextInputLayout's bounds.
cutoutBounds.offset(-getPaddingLeft(), -getPaddingTop());
boxLabelCutoutHeight = boxStrokeWidthPx;
cutoutBounds.top = 0;
cutoutBounds.bottom = boxLabelCutoutHeight;
// Offset the cutout bounds by the TextInputLayout's left padding to ensure that the cutout is
// inset relative to the TextInputLayout's bounds.
cutoutBounds.offset(-getPaddingLeft(), 0);
((CutoutDrawable) boxBackground).setCutout(cutoutBounds);
}

/** If stroke changed width, cutout bounds need to be recalculated. **/
private void updateCutout() {
if (cutoutEnabled() && !hintExpanded && boxLabelCutoutWidth != boxStrokeWidthPx) {
if (cutoutEnabled() && !hintExpanded && boxLabelCutoutHeight != boxStrokeWidthPx) {
closeCutout();
openCutout();
}
Expand Down

0 comments on commit 982f74d

Please sign in to comment.