From b8e97eb18cd840a62d41e01756e95084963b9b70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96nder=20Ceylan?= Date: Thu, 3 Aug 2017 13:26:35 +0200 Subject: [PATCH] Hardware keyboard auto blur issue on keyboard hide #289 --- src/ios/IonicKeyboard.h | 1 + src/ios/IonicKeyboard.m | 34 ++++++++++++++++++++++------------ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/ios/IonicKeyboard.h b/src/ios/IonicKeyboard.h index 63935dc..2846b59 100644 --- a/src/ios/IonicKeyboard.h +++ b/src/ios/IonicKeyboard.h @@ -10,6 +10,7 @@ @property (readwrite, assign) BOOL hideKeyboardAccessoryBar; @property (readwrite, assign) BOOL disableScroll; +@property (readonly, assign, nonatomic) BOOL keyboardIsVisible; //@property (readwrite, assign) BOOL styleDark; @end diff --git a/src/ios/IonicKeyboard.m b/src/ios/IonicKeyboard.m index d072ca7..eed41b8 100644 --- a/src/ios/IonicKeyboard.m +++ b/src/ios/IonicKeyboard.m @@ -2,6 +2,10 @@ // #import "UIWebViewExtension.h" #import +@interface IonicKeyboard () +@property (nonatomic, readwrite, assign) BOOL keyboardIsVisible; +@end + @implementation IonicKeyboard @synthesize hideKeyboardAccessoryBar = _hideKeyboardAccessoryBar; @@ -31,24 +35,30 @@ - (void)pluginInitialize { object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification* notification) { - - CGRect keyboardFrame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue]; - keyboardFrame = [self.viewController.view convertRect:keyboardFrame fromView:nil]; - - [weakSelf.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.plugins.Keyboard.isVisible = true; cordova.fireWindowEvent('native.keyboardshow', { 'keyboardHeight': %@ }); ", [@(keyboardFrame.size.height) stringValue]]]; - - //deprecated - [weakSelf.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireWindowEvent('native.showkeyboard', { 'keyboardHeight': %@ }); ", [@(keyboardFrame.size.height) stringValue]]]; + if (!self.keyboardIsVisible) { + CGRect keyboardFrame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue]; + keyboardFrame = [self.viewController.view convertRect:keyboardFrame fromView:nil]; + + [weakSelf.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.plugins.Keyboard.isVisible = true; cordova.fireWindowEvent('native.keyboardshow', { 'keyboardHeight': %@ }); ", [@(keyboardFrame.size.height) stringValue]]]; + + //deprecated + [weakSelf.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireWindowEvent('native.showkeyboard', { 'keyboardHeight': %@ }); ", [@(keyboardFrame.size.height) stringValue]]]; + self.keyboardIsVisible = true; + } }]; _keyboardHideObserver = [nc addObserverForName:UIKeyboardWillHideNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification* notification) { - [weakSelf.commandDelegate evalJs:@"cordova.plugins.Keyboard.isVisible = false; cordova.fireWindowEvent('native.keyboardhide'); "]; - - //deprecated - [weakSelf.commandDelegate evalJs:@"cordova.fireWindowEvent('native.hidekeyboard'); "]; + if (self.keyboardIsVisible) { + + [weakSelf.commandDelegate evalJs:@"cordova.plugins.Keyboard.isVisible = false; cordova.fireWindowEvent('native.keyboardhide'); "]; + + //deprecated + [weakSelf.commandDelegate evalJs:@"cordova.fireWindowEvent('native.hidekeyboard'); "]; + self.keyboardIsVisible = false; + } }]; }