From 97b29e5f717679908d7327f8f30d78b787f72bc6 Mon Sep 17 00:00:00 2001 From: arekkubaczkowski Date: Thu, 3 Mar 2022 23:17:50 +0100 Subject: [PATCH] [Android] fix: card field focus jumps back to the card number field (#630) * fix: card field focus jumping back to the card numbr field * chore: re-run tests * chore: set profile * chore: revert * chore: set galaxy nexus as a profile * Update example/index.js * [skip actions] Update android/src/main/java/com/reactnativestripesdk/StripeSdkCardView.kt Co-authored-by: charliecruzan-stripe <97612659+charliecruzan-stripe@users.noreply.github.com> --- .github/workflows/e2e-tests.yml | 1 + .../reactnativestripesdk/StripeSdkCardView.kt | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index 19ec828ce..239a401bc 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -50,6 +50,7 @@ jobs: with: api-level: 29 arch: x86_64 + profile: Galaxy Nexus target: google_apis force-avd-creation: false disable-animations: true diff --git a/android/src/main/java/com/reactnativestripesdk/StripeSdkCardView.kt b/android/src/main/java/com/reactnativestripesdk/StripeSdkCardView.kt index 6ec117771..79620211c 100644 --- a/android/src/main/java/com/reactnativestripesdk/StripeSdkCardView.kt +++ b/android/src/main/java/com/reactnativestripesdk/StripeSdkCardView.kt @@ -183,7 +183,7 @@ class StripeSdkCardView(private val context: ThemedReactContext) : FrameLayout(c return cardDetails } - fun onCardChanged() { + fun onValidCardChange() { mCardWidget.paymentMethodCard?.let { cardParams = it cardAddress = Address.Builder() @@ -201,6 +201,10 @@ class StripeSdkCardView(private val context: ThemedReactContext) : FrameLayout(c cardDetails["brand"] = null cardDetails["last4"] = null } + sendCardDetailsEvent() + } + + private fun sendCardDetailsEvent() { mEventDispatcher?.dispatchEvent( CardChangedEvent(id, cardDetails, mCardWidget.postalCodeEnabled, cardParams != null, dangerouslyGetFullCardDetails)) } @@ -211,7 +215,10 @@ class StripeSdkCardView(private val context: ThemedReactContext) : FrameLayout(c cardDetails["validCVC"] = if (invalidFields.contains(CardValidCallback.Fields.Cvc)) "Invalid" else "Valid" cardDetails["validExpiryDate"] = if (invalidFields.contains(CardValidCallback.Fields.Expiry)) "Invalid" else "Valid" if (isValid) { - onCardChanged() + onValidCardChange() + } else { + cardParams = null + cardAddress = null } } @@ -240,7 +247,7 @@ class StripeSdkCardView(private val context: ThemedReactContext) : FrameLayout(c cardDetails["expiryYear"] = var1.toString().split("/")[1].toIntOrNull() } - onCardChanged() + sendCardDetailsEvent() } }) @@ -249,7 +256,7 @@ class StripeSdkCardView(private val context: ThemedReactContext) : FrameLayout(c override fun afterTextChanged(p0: Editable?) {} override fun onTextChanged(var1: CharSequence?, var2: Int, var3: Int, var4: Int) { cardDetails["postalCode"] = var1.toString() - onCardChanged() + sendCardDetailsEvent() } }) @@ -260,7 +267,7 @@ class StripeSdkCardView(private val context: ThemedReactContext) : FrameLayout(c if (dangerouslyGetFullCardDetails) { cardDetails["number"] = var1.toString().replace(" ", "") } - onCardChanged() + sendCardDetailsEvent() } }) @@ -268,7 +275,7 @@ class StripeSdkCardView(private val context: ThemedReactContext) : FrameLayout(c override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {} override fun afterTextChanged(p0: Editable?) {} override fun onTextChanged(var1: CharSequence?, var2: Int, var3: Int, var4: Int) { - onCardChanged() + sendCardDetailsEvent() } }) }