From 64aaea8f63ee414896a9587efc6c18cf633c43ef Mon Sep 17 00:00:00 2001 From: Thomas Hessler Date: Tue, 7 Nov 2017 15:34:23 -0500 Subject: [PATCH 01/11] keyboard change observer --- README.md | 17 +++++++++++++++++ src/ios/IonicKeyboard.h | 2 +- src/ios/IonicKeyboard.m | 9 +++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 460b344..06af2dc 100644 --- a/README.md +++ b/README.md @@ -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 or when the keyboard frame resizes (when switching between keyboards for example) + + window.addEventListener('native.keyboardchange', keyboardChangeHandler); + + function keyboardChangeHandler(e){ + alert('Keyboard height is: ' + e.lang); + } + + +Properties +----------- + +lang: current language of the keyboard. it's a string. Supported Platforms ------------------- diff --git a/src/ios/IonicKeyboard.h b/src/ios/IonicKeyboard.h index 63935dc..d620a3f 100644 --- a/src/ios/IonicKeyboard.h +++ b/src/ios/IonicKeyboard.h @@ -3,7 +3,7 @@ @interface IonicKeyboard : CDVPlugin { @protected - id _keyboardShowObserver, _keyboardHideObserver; + id _keyboardShowObserver, _keyboardHideObserver, _keyboardChangeObserver; IMP wkOriginalImp, uiOriginalImp, nilImp; Method wkMethod, uiMethod; } diff --git a/src/ios/IonicKeyboard.m b/src/ios/IonicKeyboard.m index d072ca7..8ff8999 100644 --- a/src/ios/IonicKeyboard.m +++ b/src/ios/IonicKeyboard.m @@ -50,6 +50,15 @@ - (void)pluginInitialize { //deprecated [weakSelf.commandDelegate evalJs:@"cordova.fireWindowEvent('native.hidekeyboard'); "]; }]; + + _keyboardChangeObserver = [nc addObserverForName:UITextInputCurrentInputModeDidChangeNotification + object:nil queue:[NSOperationQueue mainQueue] + usingBlock:^(NSNotification* notification){ + NSString * primaryLanguage = [UITextInputMode currentInputMode].primaryLanguage; + NSString * jsWithLang = [NSString stringWithFormat:@"cordova.fireWindowEvent('native.keyboardchange', {lang: %@});", primaryLanguage]; + [weakSelf.commandDelegate evalJs:jsWithLang]; + }]; + } - (BOOL)disableScroll { From 5d5a62375c333e8d01c378ec910cf86b5e4a6d64 Mon Sep 17 00:00:00 2001 From: Thomas Hessler Date: Tue, 7 Nov 2017 15:35:04 -0500 Subject: [PATCH 02/11] readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 06af2dc..a0a0fba 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Keyboard The `cordova.plugins.Keyboard` object provides functions to make interacting with the keyboard easier, and fires events to indicate that the keyboard will hide/show. - cordova plugin add ionic-plugin-keyboard --save + cordova plugin add https://github.com/thessler27/ionic-plugin-keyboard --save Methods ------- From c2899cb3d8c35f096b440868ee0ed967527a973f Mon Sep 17 00:00:00 2001 From: Thomas Hessler Date: Tue, 7 Nov 2017 15:37:22 -0500 Subject: [PATCH 03/11] readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a0a0fba..b92cc22 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,7 @@ This event fires when the keyboard will be shown or when the keyboard frame resi window.addEventListener('native.keyboardshow', keyboardShowHandler); function keyboardShowHandler(e){ - alert('Keyboard height is: ' + e.keyboardHeight); + alert('Keyboard lang is: ' + e.keyboardHeight); } From 7fbc031d4ab4126147ac13347f21b7f32938fbab Mon Sep 17 00:00:00 2001 From: Thomas Hessler Date: Thu, 9 Nov 2017 09:38:58 -0500 Subject: [PATCH 04/11] add quotes --- src/ios/IonicKeyboard.m | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ios/IonicKeyboard.m b/src/ios/IonicKeyboard.m index 8ff8999..8c93b36 100644 --- a/src/ios/IonicKeyboard.m +++ b/src/ios/IonicKeyboard.m @@ -55,7 +55,9 @@ - (void)pluginInitialize { object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification* notification){ NSString * primaryLanguage = [UITextInputMode currentInputMode].primaryLanguage; - NSString * jsWithLang = [NSString stringWithFormat:@"cordova.fireWindowEvent('native.keyboardchange', {lang: %@});", primaryLanguage]; + NSString * jsWithLang = [NSString stringWithFormat:@"cordova.fireWindowEvent('native.keyboardchange', {lang: '%@'});", primaryLanguage]; + NSLog(@"Keyboard change"); + NSLog(@"js with lang %@", jsWithLang); [weakSelf.commandDelegate evalJs:jsWithLang]; }]; From ddf9c0ba05bd1a24e2ac90ff723f2f99260f5aac Mon Sep 17 00:00:00 2001 From: Thomas Hessler Date: Thu, 9 Nov 2017 09:41:18 -0500 Subject: [PATCH 05/11] remove logs --- src/ios/IonicKeyboard.m | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/ios/IonicKeyboard.m b/src/ios/IonicKeyboard.m index 8c93b36..9c70455 100644 --- a/src/ios/IonicKeyboard.m +++ b/src/ios/IonicKeyboard.m @@ -56,8 +56,6 @@ - (void)pluginInitialize { usingBlock:^(NSNotification* notification){ NSString * primaryLanguage = [UITextInputMode currentInputMode].primaryLanguage; NSString * jsWithLang = [NSString stringWithFormat:@"cordova.fireWindowEvent('native.keyboardchange', {lang: '%@'});", primaryLanguage]; - NSLog(@"Keyboard change"); - NSLog(@"js with lang %@", jsWithLang); [weakSelf.commandDelegate evalJs:jsWithLang]; }]; From affb3c456d82c7f82b8e43e08e503db04329664f Mon Sep 17 00:00:00 2001 From: Thomas Hessler Date: Thu, 9 Nov 2017 09:58:09 -0500 Subject: [PATCH 06/11] readme update --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b92cc22..cabd540 100644 --- a/README.md +++ b/README.md @@ -108,7 +108,7 @@ This event fires when the keyboard will be shown or when the keyboard frame resi window.addEventListener('native.keyboardchange', keyboardChangeHandler); function keyboardChangeHandler(e){ - alert('Keyboard height is: ' + e.lang); + alert('Keyboard lang is: ' + e.lang); } From 7edb220962b518cf9668bc14addcd7a5248b2658 Mon Sep 17 00:00:00 2001 From: Thomas Hessler Date: Thu, 9 Nov 2017 12:45:16 -0500 Subject: [PATCH 07/11] add height --- README.md | 1 + src/ios/IonicKeyboard.m | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cabd540..2d41dc3 100644 --- a/README.md +++ b/README.md @@ -109,6 +109,7 @@ This event fires when the keyboard will be shown or when the keyboard frame resi function keyboardChangeHandler(e){ alert('Keyboard lang is: ' + e.lang); + alert('Keyboard height is: ' + e.height); } diff --git a/src/ios/IonicKeyboard.m b/src/ios/IonicKeyboard.m index 9c70455..21700e0 100644 --- a/src/ios/IonicKeyboard.m +++ b/src/ios/IonicKeyboard.m @@ -54,8 +54,10 @@ - (void)pluginInitialize { _keyboardChangeObserver = [nc addObserverForName:UITextInputCurrentInputModeDidChangeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification* notification){ + CGRect keyboardFrame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue]; + keyboardFrame = [self.viewController.view convertRect:keyboardFrame fromView:nil]; NSString * primaryLanguage = [UITextInputMode currentInputMode].primaryLanguage; - NSString * jsWithLang = [NSString stringWithFormat:@"cordova.fireWindowEvent('native.keyboardchange', {lang: '%@'});", primaryLanguage]; + NSString * jsWithLang = [NSString stringWithFormat:@"cordova.fireWindowEvent('native.keyboardchange', {lang: '%@', height: %@});", primaryLanguage, [@(keyboardFrame.size.height) stringValue]]; [weakSelf.commandDelegate evalJs:jsWithLang]; }]; From f66054ecf1b3203aa467af614b03a677ab1397f5 Mon Sep 17 00:00:00 2001 From: Thomas Hessler Date: Thu, 9 Nov 2017 15:10:37 -0500 Subject: [PATCH 08/11] more --- README.md | 7 +++---- src/ios/IonicKeyboard.m | 14 ++++++++------ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 2d41dc3..a3accd4 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Keyboard The `cordova.plugins.Keyboard` object provides functions to make interacting with the keyboard easier, and fires events to indicate that the keyboard will hide/show. - cordova plugin add https://github.com/thessler27/ionic-plugin-keyboard --save + cordova plugin add ionic-plugin-keyboard --save Methods ------- @@ -91,7 +91,7 @@ This event fires when the keyboard will be shown or when the keyboard frame resi window.addEventListener('native.keyboardshow', keyboardShowHandler); function keyboardShowHandler(e){ - alert('Keyboard lang is: ' + e.keyboardHeight); + alert('Keyboard height is: ' + e.keyboardHeight); } @@ -103,12 +103,11 @@ keyboardHeight: the height of the keyboard in pixels native.keyboardchange (iOS ONLY) ================= -This event fires when the keyboard will be shown or when the keyboard frame resizes (when switching between keyboards for example) +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 lang is: ' + e.lang); alert('Keyboard height is: ' + e.height); } diff --git a/src/ios/IonicKeyboard.m b/src/ios/IonicKeyboard.m index 21700e0..8a42168 100644 --- a/src/ios/IonicKeyboard.m +++ b/src/ios/IonicKeyboard.m @@ -51,18 +51,20 @@ - (void)pluginInitialize { [weakSelf.commandDelegate evalJs:@"cordova.fireWindowEvent('native.hidekeyboard'); "]; }]; - _keyboardChangeObserver = [nc addObserverForName:UITextInputCurrentInputModeDidChangeNotification - object:nil queue:[NSOperationQueue mainQueue] + _keyboardChangeObserver = [nc addObserverForName:UIKeyboardDidChangeFrameNotification + object:nil + queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification* notification){ - CGRect keyboardFrame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue]; - keyboardFrame = [self.viewController.view convertRect:keyboardFrame fromView:nil]; - NSString * primaryLanguage = [UITextInputMode currentInputMode].primaryLanguage; - NSString * jsWithLang = [NSString stringWithFormat:@"cordova.fireWindowEvent('native.keyboardchange', {lang: '%@', height: %@});", primaryLanguage, [@(keyboardFrame.size.height) stringValue]]; + NSLog(@"keyboard will change"); + CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size; + NSString * jsWithLang = [NSString stringWithFormat:@"cordova.fireWindowEvent('native.keyboardchange', {height: %@});", [@(keyboardSize.height) stringValue]]; + NSLog(@"ui keyboard will change frame not height: %f", keyboardSize.height); [weakSelf.commandDelegate evalJs:jsWithLang]; }]; } + - (BOOL)disableScroll { return _disableScroll; } From 3fa68844bf0f6904d590bd166b9d54766869e5c5 Mon Sep 17 00:00:00 2001 From: Thomas Hessler Date: Thu, 9 Nov 2017 15:13:28 -0500 Subject: [PATCH 09/11] to keyboardHeight --- README.md | 2 +- src/ios/IonicKeyboard.m | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a3accd4..661db35 100644 --- a/README.md +++ b/README.md @@ -108,7 +108,7 @@ This event fires when the keyboard will be shown when the keyboard frame resizes window.addEventListener('native.keyboardchange', keyboardChangeHandler); function keyboardChangeHandler(e){ - alert('Keyboard height is: ' + e.height); + alert('Keyboard height is: ' + e.keyboardHeight); } diff --git a/src/ios/IonicKeyboard.m b/src/ios/IonicKeyboard.m index 8a42168..3e95f09 100644 --- a/src/ios/IonicKeyboard.m +++ b/src/ios/IonicKeyboard.m @@ -57,7 +57,7 @@ - (void)pluginInitialize { usingBlock:^(NSNotification* notification){ NSLog(@"keyboard will change"); CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size; - NSString * jsWithLang = [NSString stringWithFormat:@"cordova.fireWindowEvent('native.keyboardchange', {height: %@});", [@(keyboardSize.height) stringValue]]; + NSString * jsWithLang = [NSString stringWithFormat:@"cordova.fireWindowEvent('native.keyboardchange', {'keyboardHeight': %@});", [@(keyboardSize.height) stringValue]]; NSLog(@"ui keyboard will change frame not height: %f", keyboardSize.height); [weakSelf.commandDelegate evalJs:jsWithLang]; }]; From cd564dfb99176b5e7d3c3de352098a28b4f09616 Mon Sep 17 00:00:00 2001 From: Thomas Hessler Date: Thu, 9 Nov 2017 15:16:44 -0500 Subject: [PATCH 10/11] cleaning --- src/ios/IonicKeyboard.m | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/ios/IonicKeyboard.m b/src/ios/IonicKeyboard.m index 3e95f09..56e6423 100644 --- a/src/ios/IonicKeyboard.m +++ b/src/ios/IonicKeyboard.m @@ -55,11 +55,8 @@ - (void)pluginInitialize { object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification* notification){ - NSLog(@"keyboard will change"); - CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size; - NSString * jsWithLang = [NSString stringWithFormat:@"cordova.fireWindowEvent('native.keyboardchange', {'keyboardHeight': %@});", [@(keyboardSize.height) stringValue]]; - NSLog(@"ui keyboard will change frame not height: %f", keyboardSize.height); - [weakSelf.commandDelegate evalJs:jsWithLang]; + CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size; + [weakSelf.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireWindowEvent('native.keyboardchange', {'keyboardHeight': %@});", [@(keyboardSize.height) stringValue]]]; }]; } From 962279d0ddb0199e5bc6884fa48daaa038c8b7c4 Mon Sep 17 00:00:00 2001 From: Thomas Hessler Date: Thu, 9 Nov 2017 15:19:38 -0500 Subject: [PATCH 11/11] cleaning --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 661db35..e2225dd 100644 --- a/README.md +++ b/README.md @@ -115,7 +115,7 @@ This event fires when the keyboard will be shown when the keyboard frame resizes Properties ----------- -lang: current language of the keyboard. it's a string. +keyboardHeight: the height of the keyboard in pixels Supported Platforms -------------------