Skip to content

Commit

Permalink
Hardware keyboard auto blur issue on keyboard hide ionic-team#289
Browse files Browse the repository at this point in the history
  • Loading branch information
Önder Ceylan committed Aug 3, 2017
1 parent 9b7c416 commit b8e97eb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/ios/IonicKeyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 22 additions & 12 deletions src/ios/IonicKeyboard.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
// #import "UIWebViewExtension.h"
#import <Cordova/CDVAvailability.h>

@interface IonicKeyboard () <UIScrollViewDelegate>
@property (nonatomic, readwrite, assign) BOOL keyboardIsVisible;
@end

@implementation IonicKeyboard

@synthesize hideKeyboardAccessoryBar = _hideKeyboardAccessoryBar;
Expand Down Expand Up @@ -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;
}
}];
}

Expand Down

0 comments on commit b8e97eb

Please sign in to comment.