|
2 | 2 | // #import "UIWebViewExtension.h"
|
3 | 3 | #import <Cordova/CDVAvailability.h>
|
4 | 4 |
|
| 5 | +@interface IonicKeyboard () <UIScrollViewDelegate> |
| 6 | +@property (nonatomic, readwrite, assign) BOOL keyboardIsVisible; |
| 7 | +@end |
| 8 | + |
5 | 9 | @implementation IonicKeyboard
|
6 | 10 |
|
7 | 11 | @synthesize hideKeyboardAccessoryBar = _hideKeyboardAccessoryBar;
|
@@ -31,24 +35,30 @@ - (void)pluginInitialize {
|
31 | 35 | object:nil
|
32 | 36 | queue:[NSOperationQueue mainQueue]
|
33 | 37 | usingBlock:^(NSNotification* notification) {
|
| 38 | + if (!self.keyboardIsVisible) { |
| 39 | + CGRect keyboardFrame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue]; |
| 40 | + keyboardFrame = [self.viewController.view convertRect:keyboardFrame fromView:nil]; |
34 | 41 |
|
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]]]; |
37 | 43 |
|
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 | + } |
42 | 48 | }];
|
43 | 49 |
|
44 | 50 | _keyboardHideObserver = [nc addObserverForName:UIKeyboardWillHideNotification
|
45 | 51 | object:nil
|
46 | 52 | queue:[NSOperationQueue mainQueue]
|
47 | 53 | 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'); "]; |
49 | 57 |
|
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 | + } |
52 | 62 | }];
|
53 | 63 | }
|
54 | 64 |
|
|
0 commit comments