Skip to content

Commit

Permalink
[Android] fix: card field focus jumps back to the card number field (#…
Browse files Browse the repository at this point in the history
…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 <[email protected]>
  • Loading branch information
arekkubaczkowski and charliecruzan-stripe authored Mar 3, 2022
1 parent 7fa5fcc commit 97b29e5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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))
}
Expand All @@ -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
}
}

Expand Down Expand Up @@ -240,7 +247,7 @@ class StripeSdkCardView(private val context: ThemedReactContext) : FrameLayout(c
cardDetails["expiryYear"] = var1.toString().split("/")[1].toIntOrNull()
}

onCardChanged()
sendCardDetailsEvent()
}
})

Expand All @@ -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()
}
})

Expand All @@ -260,15 +267,15 @@ class StripeSdkCardView(private val context: ThemedReactContext) : FrameLayout(c
if (dangerouslyGetFullCardDetails) {
cardDetails["number"] = var1.toString().replace(" ", "")
}
onCardChanged()
sendCardDetailsEvent()
}
})

mCardWidget.setCvcNumberTextWatcher(object : TextWatcher {
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()
}
})
}
Expand Down

0 comments on commit 97b29e5

Please sign in to comment.