Skip to content
This repository has been archived by the owner on Apr 2, 2018. It is now read-only.

Fix event.keyboardHeight value for iPad hardware keyboard bar #273

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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: 6 additions & 4 deletions src/ios/IonicKeyboard.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ - (void)pluginInitialize {
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification* notification) {

CGRect keyboardFrame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
keyboardFrame = [self.viewController.view convertRect:keyboardFrame fromView:nil];
CGRect screen = [[UIScreen mainScreen] bounds];
CGRect keyboard = ((NSValue*)notification.userInfo[@"UIKeyboardFrameEndUserInfoKey"]).CGRectValue;
CGRect intersection = CGRectIntersection(screen, keyboard);
CGFloat height = MIN(intersection.size.width, intersection.size.height);

[weakSelf.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.plugins.Keyboard.isVisible = true; cordova.fireWindowEvent('native.keyboardshow', { 'keyboardHeight': %@ }); ", [@(keyboardFrame.size.height) stringValue]]];
[weakSelf.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.plugins.Keyboard.isVisible = true; cordova.fireWindowEvent('native.keyboardshow', { 'keyboardHeight': %f }); ", height]];

//deprecated
[weakSelf.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireWindowEvent('native.showkeyboard', { 'keyboardHeight': %@ }); ", [@(keyboardFrame.size.height) stringValue]]];
[weakSelf.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireWindowEvent('native.showkeyboard', { 'keyboardHeight': %f }); ", height]];
}];

_keyboardHideObserver = [nc addObserverForName:UIKeyboardWillHideNotification
Expand Down