Skip to content

Commit

Permalink
Make STPPaymentCardTextField not attempt to become first responder wh…
Browse files Browse the repository at this point in the history
…en being dismissed (#1393)
  • Loading branch information
davidme-stripe authored Sep 27, 2019
1 parent 587e49c commit f953403
Showing 1 changed file with 9 additions and 1 deletion.
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

0 comments on commit f953403

Please sign in to comment.