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

Fix issue with ZIP/Postal code field becoming first responder #4740

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

davidme-stripe
Copy link
Contributor

@davidme-stripe davidme-stripe commented Mar 28, 2025

Summary

  • We were always setting the firstResponder to the next field when a PickerFieldView lost focus, which wasn't correct: If a user tapped a different field (like the card field), the field after the current PickerFieldView would be selected instead, and sometimes both fields would have a caret. We should instead select the next field only if a user taps the "Done" button in the accessory view.
  • We wait a turn of the runloop (with DispatchQueue.main.async) before switching to the next field. This causes an animation glitch where the picker view animates out and the keyboard immediately animates up. If we switch to the next field immediately, we'll skip that animation.
  • This was a workaround for a different bug, where tapping the "Postal code" field as it's becoming a "ZIP" field didn't work. This happened because the Postal code field is destroyed and a ZIP code field is created in its place.
  • While switching fields, we're also incorrectly animating the size of the scrollview when the keyboard's animation duration is 0.

To fix this:

  • We won't make an async call to switch fields when autoAdvancing.
  • We won't autoadvance if a user taps a different cell from the PickerFieldView.
  • When a text field that is about to be destroyed attempts to becomeFirstResponder, we'll store a boolean to remember that it wanted to be firstResponder. When we're destroying/recreating a Section's stackView, we'll look for views with this boolean, and if any exist, we'll manually set that field as the first responder after the new stackView is ready.
  • We won't animate the size of the scrollview if the keyboard's animation duration is 0.
  • This animation glitch still occurs if you go from a PickerFieldView and tap a field that is being destroyed — if I make the field the firstResponder within the animation block, it gets a caret but doesn't actually become the first responder. This appears to be a bug in UIKit, so we'll wait until after the add field animation completes before running the firstResponder.
Before After
CleanShot 2025-03-28 at 16 45 30 CleanShot 2025-03-28 at 16 41 53

Motivation

MOBILESDK-1665

Testing

Existing CI tests, tested these fields in simulator (with physical keyboard) and on device:

  • Klarna
  • CBC in PaymentSheet
  • State
  • Country
  • Country code in phone number

Changelog

None, too small

@davidme-stripe davidme-stripe changed the title Fix tests Fix issue with ZIP/Postal code field becoming first responder Mar 28, 2025
@davidme-stripe davidme-stripe force-pushed the davidme/first-responder-fix-2 branch from 51d49ba to efadd28 Compare March 28, 2025 17:57
@stripe stripe deleted a comment from github-actions bot Mar 28, 2025
@davidme-stripe davidme-stripe marked this pull request as ready for review March 29, 2025 00:10
@davidme-stripe davidme-stripe requested review from a team as code owners March 29, 2025 00:10
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

Successfully merging this pull request may close these issues.

1 participant