Skip to content

Commit 371cde5

Browse files
author
VinhBT
committed
merge pull request Hardware keyboard auto blur issue on keyboard hide ionic-team#289 ionic-team#290
1 parent 9b7c416 commit 371cde5

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

src/ios/IonicKeyboard.h

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
@property (readwrite, assign) BOOL hideKeyboardAccessoryBar;
1212
@property (readwrite, assign) BOOL disableScroll;
13+
@property (readonly, assign, nonatomic) BOOL keyboardIsVisible;
1314
//@property (readwrite, assign) BOOL styleDark;
1415

1516
@end

src/ios/IonicKeyboard.m

+19-9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
// #import "UIWebViewExtension.h"
33
#import <Cordova/CDVAvailability.h>
44

5+
@interface IonicKeyboard () <UIScrollViewDelegate>
6+
@property (nonatomic, readwrite, assign) BOOL keyboardIsVisible;
7+
@end
8+
59
@implementation IonicKeyboard
610

711
@synthesize hideKeyboardAccessoryBar = _hideKeyboardAccessoryBar;
@@ -31,24 +35,30 @@ - (void)pluginInitialize {
3135
object:nil
3236
queue:[NSOperationQueue mainQueue]
3337
usingBlock:^(NSNotification* notification) {
38+
if (!self.keyboardIsVisible) {
39+
CGRect keyboardFrame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
40+
keyboardFrame = [self.viewController.view convertRect:keyboardFrame fromView:nil];
3441

35-
CGRect keyboardFrame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
36-
keyboardFrame = [self.viewController.view convertRect:keyboardFrame fromView:nil];
42+
[weakSelf.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.plugins.Keyboard.isVisible = true; cordova.fireWindowEvent('native.keyboardshow', { 'keyboardHeight': %@ }); ", [@(keyboardFrame.size.height) stringValue]]];
3743

38-
[weakSelf.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.plugins.Keyboard.isVisible = true; cordova.fireWindowEvent('native.keyboardshow', { 'keyboardHeight': %@ }); ", [@(keyboardFrame.size.height) stringValue]]];
39-
40-
//deprecated
41-
[weakSelf.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireWindowEvent('native.showkeyboard', { 'keyboardHeight': %@ }); ", [@(keyboardFrame.size.height) stringValue]]];
44+
//deprecated
45+
[weakSelf.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireWindowEvent('native.showkeyboard', { 'keyboardHeight': %@ }); ", [@(keyboardFrame.size.height) stringValue]]];
46+
self.keyboardIsVisible = true;
47+
}
4248
}];
4349

4450
_keyboardHideObserver = [nc addObserverForName:UIKeyboardWillHideNotification
4551
object:nil
4652
queue:[NSOperationQueue mainQueue]
4753
usingBlock:^(NSNotification* notification) {
48-
[weakSelf.commandDelegate evalJs:@"cordova.plugins.Keyboard.isVisible = false; cordova.fireWindowEvent('native.keyboardhide'); "];
54+
if (self.keyboardIsVisible) {
55+
56+
[weakSelf.commandDelegate evalJs:@"cordova.plugins.Keyboard.isVisible = false; cordova.fireWindowEvent('native.keyboardhide'); "];
4957

50-
//deprecated
51-
[weakSelf.commandDelegate evalJs:@"cordova.fireWindowEvent('native.hidekeyboard'); "];
58+
//deprecated
59+
[weakSelf.commandDelegate evalJs:@"cordova.fireWindowEvent('native.hidekeyboard'); "];
60+
self.keyboardIsVisible = false;
61+
}
5262
}];
5363
}
5464

0 commit comments

Comments
 (0)