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

STPPaymentCardTextField sends keyboardWillHideNotification when begin editing the field. #1388

Closed
russellyeo opened this issue Sep 25, 2019 · 10 comments
Labels
triaged Issue has been reviewed by Stripe and is being tracked internally

Comments

@russellyeo
Copy link

russellyeo commented Sep 25, 2019

Summary

When tapping on STPPaymentCardTextField to begin editing the field one would expect UIResponder.keyboardWillShowNotification to be sent, but instead the UIResponder.keyboardWillHideNotification is sent. This results in great difficulty in managing the View in relation to the keyboard.

Code to reproduce

NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide(_:)), name: UIResponder.keyboardWillHideNotification, object: nil)

iOS version

<= iOS 12

Installation method

Carthage

SDK version

17.0.1

@russellyeo russellyeo changed the title STPPaymentCardTextField sends keyboardWillHideNotification when the field becomes first responder. STPPaymentCardTextField sends keyboardWillHideNotification when begin editing the field. Sep 25, 2019
@davidme-stripe
Copy link
Contributor

Hey @rus64, I'm seeing this happen when a hardware keyboard is connected (or when "Keyboard" -> "Connect Hardware Keyboard" is enabled in the Simulator menu, which is the default option), but not when it's disabled. Without a hardware keyboard, tapping on the field triggers a UIResponder.keyboardWillShowNotification. Are you seeing this without a hardware keyboard connected?

@davidme-stripe davidme-stripe added the triaged Issue has been reviewed by Stripe and is being tracked internally label Sep 25, 2019
@russellyeo
Copy link
Author

russellyeo commented Sep 26, 2019

Hi @davidme-stripe, thanks for your response.

Making sure that setting was disabled did indeed avoid the mentioned issue, however, now when dismissing the keyboard both the UIResponder.keyboardWillShowNotification and UIResponder.keyboardWillHideNotification are sent, causing glitchy behaviour. I am also testing this on a device to avoid potential problems with the simulator and seeing the same issue.

@russellyeo
Copy link
Author

russellyeo commented Sep 26, 2019

On further inspection this is the order of events that I am seeing:

  • Begin editing cardTextField (STPPaymentCardTextField)
  • keyboardWillShowNotification is sent
  • keyboardDidShowNotification is sent
  • Tap Cancel - this calls cardTextField.resignFirstResponder()
  • keyboardWillHideNotification is sent
  • keyboardDidHideNotification is sent
  • cardTextField.isFirstResponder is still true here and the keyboard is visible
  • Call viewController.dismiss()
  • keyboardWillShowNotification is sent
  • keyboardDidShowNotification is sent
  • keyboardWillHideNotification is sent

It seems to me that maybe the keyboard is not properly dismissed after resigning the card text field. The last three notifications then cause weird behaviour in our app.

Tested on an iPhone 6s on iOS 12.2 (real device not sim).

@russellyeo
Copy link
Author

russellyeo commented Sep 26, 2019

A temporary workaround that I've found:

Instead of calling resignFirstResponder on the Card Text Field, we can call endEditing(true) on the ViewController's View (superview of the card text field) forcing the view's active subview to resign.

From the UIKit.UITextField documentation:

use to make the view or any subview that is the first responder resign (optionally force)

@davidme-stripe
Copy link
Contributor

Thanks for the additional info! I've tried to patch this in the branch davidme/card-text-field-less-noisy. Let me know if it fixes the issue for you.

@russellyeo
Copy link
Author

russellyeo commented Sep 30, 2019

@davidme-stripe, thanks for taking a look! I'm going to try it this morning.

@russellyeo
Copy link
Author

russellyeo commented Sep 30, 2019

Unfortunately the patch #1393 does not fix the issue for me. Still seeing unexpected keyboard behaviour when calling resignFirstResponder() on the STPPaymentCardTextField.

@davidme-stripe
Copy link
Contributor

@rus64, I can't seem to reproduce the issue after the patch.

  • I tap the card field and receive a keyboardWillShowNotification.
  • I tap the expiration date field and receive a second keyboardWillShowNotification. This seems like normal UIKit behavior: The keyboard dimensions may change when moving to a different text field, and the userInfo of the notification contains the new dimensions.
  • I set a timer to wait 5 seconds before calling cardTextField.resignFirstResponder(). This sends a single keyboardWillHideNotification.
  • I do the same setup, then dismiss the entire view controller. This sends a single keyboardWillHideNotification.

What behavior are you seeing after the new patch?

@russellyeo
Copy link
Author

Ah, I do apologise; looks like I did not properly build the framework from the master branch. I tested again this morning and confirm that the issue is fixed. Thank you for your time and attention on this!

@davidme-stripe
Copy link
Contributor

This is fixed in 18.0.0. Thanks for filing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triaged Issue has been reviewed by Stripe and is being tracked internally
Projects
None yet
Development

No branches or pull requests

2 participants