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

Call the card input widget focus listener when focus is gained. #3520

Merged
merged 2 commits into from
Mar 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,13 @@ class CardInputWidget @JvmOverloads constructor(
}
}

postalCodeEditText.internalFocusChangeListeners.add { _, hasFocus ->
if (hasFocus) {
scrollEnd()
cardInputListener?.onFocusChange(CardInputListener.FocusField.PostalCode)
}
}
Comment on lines +770 to +775
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be applied to CardMultilineWidget as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good news is that it is covered there already.


expiryDateEditText.setDeleteEmptyListener(BackUpFieldDeleteListener(cardNumberEditText))
cvcEditText.setDeleteEmptyListener(BackUpFieldDeleteListener(expiryDateEditText))
postalCodeEditText.setDeleteEmptyListener(BackUpFieldDeleteListener(cvcEditText))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1314,6 +1314,7 @@ internal class CardInputWidgetTest {
.isEqualTo(
listOf(
CardInputListener.FocusField.Cvc,
CardInputListener.FocusField.PostalCode,
CardInputListener.FocusField.CardNumber
)
)
Expand Down Expand Up @@ -1584,6 +1585,38 @@ internal class CardInputWidgetTest {
.isEqualTo("123")
}

@Test
fun `Verify on postal code focus change listeners trigger the callback`() {
cardInputWidget.postalCodeEditText.getParentOnFocusChangeListener().onFocusChange(cardInputWidget.postalCodeEditText, true)

assertThat(cardInputListener.focusedFields)
.contains(CardInputListener.FocusField.PostalCode)
}

@Test
fun `Verify on cvc focus change listeners trigger the callback`() {
cardInputWidget.cvcEditText.getParentOnFocusChangeListener().onFocusChange(cardInputWidget.cvcEditText, true)

assertThat(cardInputListener.focusedFields)
.contains(CardInputListener.FocusField.Cvc)
}

@Test
fun `Verify on expiration date focus change listeners trigger the callback`() {
cardInputWidget.expiryDateEditText.getParentOnFocusChangeListener().onFocusChange(cardInputWidget.expiryDateEditText, true)

assertThat(cardInputListener.focusedFields)
.contains(CardInputListener.FocusField.ExpiryDate)
}

@Test
fun `Verify on card number focus change listeners trigger the callback`() {
cardInputWidget.cardNumberEditText.getParentOnFocusChangeListener().onFocusChange(cardInputWidget.cardNumberEditText, true)

assertThat(cardInputListener.focusedFields)
.contains(CardInputListener.FocusField.CardNumber)
}

private fun updateCardNumberAndIdle(cardNumber: String) {
cardNumberEditText.setText(cardNumber)
idleLooper()
Expand Down