Skip to content

Commit

Permalink
Never ignore notifications if begin and end frames are different
Browse files Browse the repository at this point in the history
Fixes an issue where scrolling to the next field would not update the content insets to include the QuickType bar if it appears.
  • Loading branch information
swoolcock authored and michaeltyson committed Sep 20, 2019
1 parent 7b895e2 commit e45a445
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions TPKeyboardAvoiding/UIScrollView+TPKeyboardAvoidingAdditions.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,17 @@ - (void)TPKeyboardAvoiding_keyboardWillShow:(NSNotification*)notification {

state.animationDuration = [[info objectForKey:kUIKeyboardAnimationDurationUserInfoKey] doubleValue];

CGRect keyboardRect = [self convertRect:[[info objectForKey:_UIKeyboardFrameEndUserInfoKey] CGRectValue] fromView:nil];
if (CGRectIsEmpty(keyboardRect)) {
CGRect beginKeyboardRect = [self convertRect:[[info objectForKey:_UIKeyboardFrameBeginUserInfoKey] CGRectValue] fromView:nil];
CGRect endKeyboardRect = [self convertRect:[[info objectForKey:_UIKeyboardFrameEndUserInfoKey] CGRectValue] fromView:nil];
if (CGRectIsEmpty(endKeyboardRect)) {
return;
}

if ( state.ignoringNotifications ) {
if ( CGRectEqualToRect(beginKeyboardRect, endKeyboardRect) && state.ignoringNotifications ) {
return;
}

state.keyboardRect = keyboardRect;
state.keyboardRect = endKeyboardRect;

if ( !state.keyboardVisible ) {
state.priorInset = self.contentInset;
Expand Down Expand Up @@ -128,14 +129,15 @@ - (void)keyboardViewDisappear:(NSString *)animationID finished:(NSNumber *)finis
}

- (void)TPKeyboardAvoiding_keyboardWillHide:(NSNotification*)notification {
CGRect keyboardRect = [self convertRect:[[[notification userInfo] objectForKey:_UIKeyboardFrameBeginUserInfoKey] CGRectValue] fromView:nil];
if (CGRectIsEmpty(keyboardRect) && !self.keyboardAvoidingState.keyboardAnimationInProgress) {
CGRect beginKeyboardRect = [self convertRect:[[[notification userInfo] objectForKey:_UIKeyboardFrameBeginUserInfoKey] CGRectValue] fromView:nil];
CGRect endKeyboardRect = [self convertRect:[[[notification userInfo] objectForKey:_UIKeyboardFrameEndUserInfoKey] CGRectValue] fromView:nil];
if (CGRectIsEmpty(beginKeyboardRect) && !self.keyboardAvoidingState.keyboardAnimationInProgress) {
return;
}

TPKeyboardAvoidingState *state = self.keyboardAvoidingState;

if ( state.ignoringNotifications ) {
if ( CGRectEqualToRect(beginKeyboardRect, endKeyboardRect) && state.ignoringNotifications ) {
return;
}

Expand Down

1 comment on commit e45a445

@ricsantos
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one @swoolcock 💪

Please sign in to comment.