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; + } }]; }