Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TextInputLayout] endIcon prevents TextInputLayout resizing after clearing multiline text #3451

Closed
NutsHell912 opened this issue Jun 13, 2023 · 4 comments

Comments

@NutsHell912
Copy link

Description:

  1. setup TextInputLayout with app:endIconMode="clear_text"
  2. insert or print long text without new line separator (for instance "aaaaaaaaaaaaa" or "aa dfg sdf" multiple times), until multiple wrapping to the next line
  3. clear focus from TextInputEditText/TextInputLayout
  4. focus on TextInputEditText again and clear all text(via endIcon or software keyboard)

Expected result: TextInputLayout is resizing to its initial height
Actual result: TextInputLayout is stuck with current height

TextInputLayoutWrongResize

Problem happens only if TextInputLayout is losing focus. Otherwise it's resizing correctly.
After some researh I figure out that after losing focus editText has wrong mMinHeight.
As far as I understand, problem is in private boolean updateEditTextHeightBasedOnIcon in TextInputLayout.java:

    // We need to make sure that the EditText's height is at least the same as the end or start
    // icon's height (whichever is bigger). This ensures focus works properly, and there is no
    // visual jump if the icon is enabled/disabled.
    int maxIconHeight = Math.max(endLayout.getMeasuredHeight(), startLayout.getMeasuredHeight());
    if (editText.getMeasuredHeight() < maxIconHeight) {
      editText.setMinimumHeight(maxIconHeight);
      return true;
    }


Source code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/advantages_input_text_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginHorizontal="16dp"
        android:layout_marginVertical="16dp"
        android:layout_marginTop="8dp"
        app:endIconMode="clear_text"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <EditText
            android:id="@+id/advantages_edit_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textMultiLine" />
    </com.google.android.material.textfield.TextInputLayout>

    <EditText
        android:id="@+id/disadvantages_edit_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginHorizontal="16dp"
        android:layout_marginTop="12dp"
        android:inputType="textMultiLine"
        app:layout_constraintTop_toBottomOf="@id/advantages_input_text_layout" />
</LinearLayout>

Minimal sample app repro:

https://github.com/NutsHell912/TextInputLayoutWrongResizing

Android API version: tested on API 30, 32, 33

Material Library version: 1.9.0

Device: emulators, TCL 306, Motorola G9

@appscapes
Copy link

Does anyone have a workaround for this issue?

@appscapes
Copy link

appscapes commented Aug 21, 2023

I was able to fix this by downgrading to 'com.google.android.material:material:1.5.0' (I was using 1.9.0 before).

Upgrading your dependency may fix the problem, but at this time, the only higher version available is still in alpha.

The only other fix is to set the height of your TextInputEditText manually.

@hectoreve
Copy link

I was able to fix this using setCompoundDrawablesRelativeWithIntrinsicBounds setting the icon in the end parameter and managing the icons with a textwatcher

@pekingme pekingme self-assigned this Oct 30, 2023
@pekingme
Copy link
Contributor

Just verified this bug still exists in the latest version. Just a little more clarification. This can only be reproduced if the number of lines changes while losing and regaining focus with the clear_text end icon mode in use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants