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

keyboard change frame observer #302

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,28 @@ This event fires when the keyboard will be shown or when the keyboard frame resi
alert('Keyboard height is: ' + e.keyboardHeight);
}


Properties
-----------

keyboardHeight: the height of the keyboard in pixels

native.keyboardchange (iOS ONLY)
=================

This event fires when the keyboard will be shown when the keyboard frame resizes (when switching between keyboards for example)

window.addEventListener('native.keyboardchange', keyboardChangeHandler);

function keyboardChangeHandler(e){
alert('Keyboard height is: ' + e.keyboardHeight);
}


Properties
-----------

keyboardHeight: the height of the keyboard in pixels

Supported Platforms
-------------------
Expand Down
2 changes: 1 addition & 1 deletion src/ios/IonicKeyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

@interface IonicKeyboard : CDVPlugin <UIScrollViewDelegate> {
@protected
id _keyboardShowObserver, _keyboardHideObserver;
id _keyboardShowObserver, _keyboardHideObserver, _keyboardChangeObserver;
IMP wkOriginalImp, uiOriginalImp, nilImp;
Method wkMethod, uiMethod;
}
Expand Down
10 changes: 10 additions & 0 deletions src/ios/IonicKeyboard.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,18 @@ - (void)pluginInitialize {
//deprecated
[weakSelf.commandDelegate evalJs:@"cordova.fireWindowEvent('native.hidekeyboard'); "];
}];

_keyboardChangeObserver = [nc addObserverForName:UIKeyboardDidChangeFrameNotification
object:nil
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification* notification){
CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
[weakSelf.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireWindowEvent('native.keyboardchange', {'keyboardHeight': %@});", [@(keyboardSize.height) stringValue]]];
}];

}


- (BOOL)disableScroll {
return _disableScroll;
}
Expand Down