Skip to content

Commit 8a01c99

Browse files
committed
Fix race condition in keyboard hide animation
Guard temp value reset in completion block to prevent corruption when keyboard is shown again during hide animation.
1 parent cd42986 commit 8a01c99

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

SCLAlertView/SCLAlertView.m

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,8 @@ - (void)keyboardWillHide:(NSNotification *)notification
721721
NSTimeInterval animationDuration = [userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
722722
UIViewAnimationOptions animationCurve = [userInfo[UIKeyboardAnimationCurveUserInfoKey] unsignedIntegerValue] << 16;
723723

724+
_keyboardIsVisible = NO;
725+
724726
[UIView animateWithDuration:animationDuration delay:0 options:animationCurve animations:^{
725727
CGRect contentFrame = self.contentView.frame;
726728
contentFrame.origin.y = self->_tmpContentViewFrameOrigin.y;
@@ -730,11 +732,12 @@ - (void)keyboardWillHide:(NSNotification *)notification
730732
circleFrame.origin.y = self->_tmpCircleViewFrameOrigin.y;
731733
self.circleViewBackground.frame = circleFrame;
732734
} completion:^(BOOL finished) {
733-
self->_tmpContentViewFrameOrigin = CGPointZero;
734-
self->_tmpCircleViewFrameOrigin = CGPointZero;
735+
// Only reset if keyboard hasn't been shown again during the animation
736+
if (!self->_keyboardIsVisible) {
737+
self->_tmpContentViewFrameOrigin = CGPointZero;
738+
self->_tmpCircleViewFrameOrigin = CGPointZero;
739+
}
735740
}];
736-
737-
_keyboardIsVisible = NO;
738741
}
739742
}
740743

0 commit comments

Comments
 (0)