Skip to content
This repository has been archived by the owner on Jun 16, 2022. It is now read-only.

Commit

Permalink
Merge pull request #4 from shapehq/fix/keyboard-size-changes
Browse files Browse the repository at this point in the history
Makes sure keyboard event is triggered when keyboard size changes
  • Loading branch information
sorenu committed Mar 7, 2016
2 parents 80fd9dc + 9720438 commit dda6e17
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion Source/NSObject+SHPKeyboardAwareness.m
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,26 @@ - (RACSignal *)shp_keyboardAwarenessSignalForView:(UIView *)view {
Class ignoredClass2 = NSClassFromString(@"_SHPKeyboardTextView"); // So does SHPKeyboard
return ![view isKindOfClass:ignoredClass1] && ![view isKindOfClass:ignoredClass2];
}];
combinedShowSignal = [RACSignal zip:@[viewSignal,keyboardSignal]];
combinedShowSignal = [[[RACSignal combineLatest:@[viewSignal, keyboardSignal]] combinePreviousWithStart:nil reduce:^id(RACTuple *previousTuple, RACTuple *currentTuple) {
RACTupleUnpack(UIView *currentView, NSDictionary *currentKeyboardInfo) = currentTuple;
RACTupleUnpack(UIView *previousView, NSDictionary *previousKeyboardInfo) = previousTuple;

// If keyboard height changes (e.g. if keyboard locale is changed) trigger keyboard event
CGRect currentEndKeyboardBounds = ((NSValue *) currentKeyboardInfo[UIKeyboardFrameEndUserInfoKey]).CGRectValue;
CGRect previousEndKeyboardBounds = ((NSValue *) previousKeyboardInfo[UIKeyboardFrameEndUserInfoKey]).CGRectValue;
BOOL keyboardHeightDidChange = CGRectGetHeight(currentEndKeyboardBounds) != CGRectGetHeight(previousEndKeyboardBounds);

// If keyboard's y origin is higher than the previous tuple (e.g. the keyboard will show) trigger keyboard event
CGRect currentBeginKeyboardBounds = ((NSValue *) currentKeyboardInfo[UIKeyboardFrameBeginUserInfoKey]).CGRectValue;
CGRect previousBeginKeyboardBounds = ((NSValue *) previousKeyboardInfo[UIKeyboardFrameBeginUserInfoKey]).CGRectValue;
BOOL keyboardOriginDidChange = CGRectGetMinY(currentBeginKeyboardBounds) > CGRectGetMinY(previousBeginKeyboardBounds);

// If user changes first responder to a new view, trigger keyboard event
BOOL viewDidChange = currentView != previousView;

// Filter results by sending nil if nothing is changed
return keyboardHeightDidChange || viewDidChange || keyboardOriginDidChange ? currentTuple : nil;
}] ignore:nil];
}

__block SHPKeyboardEvent *event = nil;
Expand Down

0 comments on commit dda6e17

Please sign in to comment.