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 shouldn't attempt to becomeFirstResponder while being dismissed #1393

Merged
merged 1 commit into from
Sep 27, 2019
Merged
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
10 changes: 9 additions & 1 deletion Stripe/STPPaymentCardTextField.m
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ - (BOOL)resignFirstResponder {
[super resignFirstResponder];
BOOL success = [self.currentFirstResponderField resignFirstResponder];
[self layoutViewsToFocusField:nil
becomeFirstResponder:NO
animated:YES
completion:nil];
[self updateImageForFieldType:STPCardFieldTypeNumber];
Expand Down Expand Up @@ -582,6 +583,7 @@ - (void)clear {
[self updateCVCPlaceholder];
__weak typeof(self) weakSelf = self;
[self layoutViewsToFocusField:@(STPCardFieldTypePostalCode)
becomeFirstResponder:YES
animated:YES
completion:^(__unused BOOL completed){
__strong typeof(self) strongSelf = weakSelf;
Expand Down Expand Up @@ -694,6 +696,7 @@ behaves identically to user entering text (and will have the same forwarding
}
} else {
[self layoutViewsToFocusField:nil
becomeFirstResponder:YES
animated:NO
completion:nil];
}
Expand Down Expand Up @@ -1159,6 +1162,7 @@ - (STPFormTextField *)buildTextField {

typedef void (^STPLayoutAnimationCompletionBlock)(BOOL completed);
- (void)layoutViewsToFocusField:(NSNumber *)focusedField
becomeFirstResponder:(BOOL)shouldBecomeFirstResponder
animated:(BOOL)animated
completion:(STPLayoutAnimationCompletionBlock)completion {

Expand All @@ -1168,7 +1172,9 @@ - (void)layoutViewsToFocusField:(NSNumber *)focusedField
&& ![self.focusedTextFieldForLayout isEqualToNumber:@(STPCardFieldTypeNumber)]
&& ([self.viewModel validationStateForField:STPCardFieldTypeNumber] != STPCardValidationStateValid)) {
fieldtoFocus = @(STPCardFieldTypeNumber);
[self.numberField becomeFirstResponder];
if (shouldBecomeFirstResponder) {
[self.numberField becomeFirstResponder];
}
}

if ((fieldtoFocus == nil && self.focusedTextFieldForLayout == nil)
Expand Down Expand Up @@ -1400,6 +1406,7 @@ - (void)textFieldDidBeginEditing:(UITextField *)textField {
BOOL isMidSubviewEditingTransition = [self getAndUpdateSubviewEditingTransitionStateFromCall:STPFieldEditingTransitionCallSiteDidBegin];

[self layoutViewsToFocusField:@(textField.tag)
becomeFirstResponder:YES
animated:YES
completion:nil];

Expand Down Expand Up @@ -1472,6 +1479,7 @@ - (void)textFieldDidEndEditing:(UITextField *)textField {

if (!isMidSubviewEditingTransition) {
[self layoutViewsToFocusField:nil
becomeFirstResponder:NO
animated:YES
completion:nil];
[self updateImageForFieldType:STPCardFieldTypeNumber];
Expand Down