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

CardField within ScrollView get re-focused on dimissing keyboard on Android #1163

Open
perqin opened this issue Oct 8, 2022 · 0 comments
Open

Comments

@perqin
Copy link
Contributor

perqin commented Oct 8, 2022

Describe the bug
After complete all fields in CardField, tap outside the CardField. Though the keyboard is dimissed, the card number edit text gets focused again and animates to expanded state.

At first I found this issue #1086 , and then found the "solution" in this issue #222 . However, StripeContainer doesn't work for me in my case where we place CardField inside a ScrollView.

To Reproduce
Steps to reproduce the behavior:

  1. Place a CardField inside a ScrollView;
  2. Tap the card number area to bring keyboard up, fill in the card number, and then fill in other fields following the input focus;
  3. Now that the focus is on postal code field and the keyboard is still active;
  4. Tap outside the CardField (but inside the ScrollView).

Expected behavior
The keyboard should be dismissed, and none of the text fields of the CardField have focus.

Screenshots
If applicable, add screenshots to help explain your problem.

Smartphone (please complete the following information):

  • Device: Google Pixel 3
  • OS: Android 12

Additional context
I've added some log to the Android native code and found that the CardField component receives blur command on tapping outside it. Then the keyboard is hidden but the card number edit text is getting focus temporarily:

// CardFieldView.kt
  fun requestBlurFromJS() {
    cardInputWidgetBinding.cardNumberEditText.hideSoftKeyboard()
    cardInputWidgetBinding.cardNumberEditText.clearFocus()
    cardInputWidgetBinding.container.requestFocus()
  }
// Extensions.kt
fun View.hideSoftKeyboard() {
  if (this.requestFocus()) {
    val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager?
    imm?.hideSoftInputFromWindow(windowToken, 0)
  }
}

This cause the card number edit text to play the CardNumberSlideStartAnimation and gain focus again.

Maybe we should find the edit text view in focus first, and call hideSoftKeyboard on it instead of simply call the function on the card number edit text view. But I'm not sure why the CardFieldView receives the blur command.

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

1 participant