Skip to content
This repository has been archived by the owner on Apr 2, 2018. It is now read-only.

Hardware keyboard auto blur issue on keyboard hide #289 #290

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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