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

Text field is empty after selecting the same country twice #28

Open
pchmielowski opened this issue Jul 20, 2022 · 2 comments
Open

Text field is empty after selecting the same country twice #28

pchmielowski opened this issue Jul 20, 2022 · 2 comments

Comments

@pchmielowski
Copy link

Code

Layout:

<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.textfield.TextInputLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/inputLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="16dp">

    <com.google.android.material.textfield.TextInputEditText
        android:id="@+id/editText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</com.google.android.material.textfield.TextInputLayout>

Activity:

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)

        val kit = PhoneNumberKit.Builder(this).build()
        kit.attachToInput(binding.inputLayout, "us")
        kit.setupCountryPicker(this)
    }
}

Reproduction steps

  1. Run the app.
  2. Click on the flag
  3. Choose any country
  4. Click on the flag again
  5. Choose the same country as in step 3.

Result

The text field is empty

Expected behavior

The text field contains area code of the selected country.

Possible cause:

After country is selected, the text field is cleared:

Then, the value of state is updated with the correct country code:


The problem is the following: the new value of state is exactly the same as the previous one (as we are reselecting the same country). MutableStateFlow does not emit a new value to its collectors if we set the same value.
That's why the following line is not called:
inputValue = state.country.code.toString()

And the text field stays empty.

@deval-ouranostech
Copy link

Hello,
Does anyone help me with this issue?
I also face this issue.

Thanks,
Deval

@deval-ouranostech
Copy link

Hi @pchmielowski ,

Did you get the solution for this issue?

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

No branches or pull requests

2 participants