| 15747 |
anikendra |
1 |
#import "IonicKeyboard.h"
|
|
|
2 |
#import "UIWebViewExtension.h"
|
|
|
3 |
#import <Cordova/CDVAvailability.h>
|
|
|
4 |
|
|
|
5 |
@implementation IonicKeyboard
|
|
|
6 |
|
|
|
7 |
@synthesize hideKeyboardAccessoryBar = _hideKeyboardAccessoryBar;
|
|
|
8 |
@synthesize disableScroll = _disableScroll;
|
|
|
9 |
//@synthesize styleDark = _styleDark;
|
|
|
10 |
|
|
|
11 |
- (void)pluginInitialize {
|
|
|
12 |
|
|
|
13 |
NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
|
|
|
14 |
__weak IonicKeyboard* weakSelf = self;
|
|
|
15 |
|
|
|
16 |
//set defaults
|
|
|
17 |
self.hideKeyboardAccessoryBar = NO;
|
|
|
18 |
self.disableScroll = NO;
|
|
|
19 |
//self.styleDark = NO;
|
|
|
20 |
|
|
|
21 |
_keyboardShowObserver = [nc addObserverForName:UIKeyboardWillShowNotification
|
|
|
22 |
object:nil
|
|
|
23 |
queue:[NSOperationQueue mainQueue]
|
|
|
24 |
usingBlock:^(NSNotification* notification) {
|
|
|
25 |
|
|
|
26 |
CGRect keyboardFrame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
|
|
|
27 |
keyboardFrame = [self.viewController.view convertRect:keyboardFrame fromView:nil];
|
|
|
28 |
|
|
|
29 |
[weakSelf.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.plugins.Keyboard.isVisible = true; cordova.fireWindowEvent('native.keyboardshow', { 'keyboardHeight': %@ }); ", [@(keyboardFrame.size.height) stringValue]]];
|
|
|
30 |
|
|
|
31 |
//deprecated
|
|
|
32 |
[weakSelf.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireWindowEvent('native.showkeyboard', { 'keyboardHeight': %@ }); ", [@(keyboardFrame.size.height) stringValue]]];
|
|
|
33 |
}];
|
|
|
34 |
|
|
|
35 |
_keyboardHideObserver = [nc addObserverForName:UIKeyboardWillHideNotification
|
|
|
36 |
object:nil
|
|
|
37 |
queue:[NSOperationQueue mainQueue]
|
|
|
38 |
usingBlock:^(NSNotification* notification) {
|
|
|
39 |
[weakSelf.commandDelegate evalJs:@"cordova.plugins.Keyboard.isVisible = false; cordova.fireWindowEvent('native.keyboardhide'); "];
|
|
|
40 |
|
|
|
41 |
//deprecated
|
|
|
42 |
[weakSelf.commandDelegate evalJs:@"cordova.fireWindowEvent('native.hidekeyboard'); "];
|
|
|
43 |
}];
|
|
|
44 |
}
|
|
|
45 |
- (BOOL)disableScroll {
|
|
|
46 |
return _disableScroll;
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
- (void)setDisableScroll:(BOOL)disableScroll {
|
|
|
50 |
if (disableScroll == _disableScroll) {
|
|
|
51 |
return;
|
|
|
52 |
}
|
|
|
53 |
if (disableScroll) {
|
|
|
54 |
self.webView.scrollView.scrollEnabled = NO;
|
|
|
55 |
self.webView.scrollView.delegate = self;
|
|
|
56 |
}
|
|
|
57 |
else {
|
|
|
58 |
self.webView.scrollView.scrollEnabled = YES;
|
|
|
59 |
self.webView.scrollView.delegate = nil;
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
_disableScroll = disableScroll;
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
|
|
|
66 |
- (BOOL)hideKeyboardAccessoryBar {
|
|
|
67 |
return _hideKeyboardAccessoryBar;
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
- (void)setHideKeyboardAccessoryBar:(BOOL)hideKeyboardAccessoryBar {
|
|
|
71 |
if (hideKeyboardAccessoryBar == _hideKeyboardAccessoryBar) {
|
|
|
72 |
return;
|
|
|
73 |
}
|
|
|
74 |
if (hideKeyboardAccessoryBar) {
|
|
|
75 |
self.webView.hackishlyHidesInputAccessoryView = YES;
|
|
|
76 |
}
|
|
|
77 |
else {
|
|
|
78 |
self.webView.hackishlyHidesInputAccessoryView = NO;
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
_hideKeyboardAccessoryBar = hideKeyboardAccessoryBar;
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
/*
|
|
|
85 |
- (BOOL)styleDark {
|
|
|
86 |
return _styleDark;
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
- (void)setStyleDark:(BOOL)styleDark {
|
|
|
90 |
if (styleDark == _styleDark) {
|
|
|
91 |
return;
|
|
|
92 |
}
|
|
|
93 |
if (styleDark) {
|
|
|
94 |
self.webView.styleDark = YES;
|
|
|
95 |
}
|
|
|
96 |
else {
|
|
|
97 |
self.webView.styleDark = NO;
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
_styleDark = styleDark;
|
|
|
101 |
}
|
|
|
102 |
*/
|
|
|
103 |
|
|
|
104 |
|
|
|
105 |
/* ------------------------------------------------------------- */
|
|
|
106 |
|
|
|
107 |
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
|
|
|
108 |
[scrollView setContentOffset: CGPointZero];
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
/* ------------------------------------------------------------- */
|
|
|
112 |
|
|
|
113 |
- (void)dealloc {
|
|
|
114 |
NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
|
|
|
115 |
|
|
|
116 |
[nc removeObserver:self name:UIKeyboardWillShowNotification object:nil];
|
|
|
117 |
[nc removeObserver:self name:UIKeyboardWillHideNotification object:nil];
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
/* ------------------------------------------------------------- */
|
|
|
121 |
|
|
|
122 |
- (void) disableScroll:(CDVInvokedUrlCommand*)command {
|
|
|
123 |
if (!command.arguments || ![command.arguments count]){
|
|
|
124 |
return;
|
|
|
125 |
}
|
|
|
126 |
id value = [command.arguments objectAtIndex:0];
|
|
|
127 |
|
|
|
128 |
self.disableScroll = [value boolValue];
|
|
|
129 |
}
|
|
|
130 |
|
|
|
131 |
- (void) hideKeyboardAccessoryBar:(CDVInvokedUrlCommand*)command {
|
|
|
132 |
if (!command.arguments || ![command.arguments count]){
|
|
|
133 |
return;
|
|
|
134 |
}
|
|
|
135 |
id value = [command.arguments objectAtIndex:0];
|
|
|
136 |
|
|
|
137 |
self.hideKeyboardAccessoryBar = [value boolValue];
|
|
|
138 |
}
|
|
|
139 |
|
|
|
140 |
- (void) close:(CDVInvokedUrlCommand*)command {
|
|
|
141 |
[self.webView endEditing:YES];
|
|
|
142 |
}
|
|
|
143 |
|
|
|
144 |
- (void) show:(CDVInvokedUrlCommand*)command {
|
|
|
145 |
NSLog(@"Showing keyboard not supported in iOS due to platform limitations.");
|
|
|
146 |
}
|
|
|
147 |
|
|
|
148 |
/*
|
|
|
149 |
- (void) styleDark:(CDVInvokedUrlCommand*)command {
|
|
|
150 |
if (!command.arguments || ![command.arguments count]){
|
|
|
151 |
return;
|
|
|
152 |
}
|
|
|
153 |
id value = [command.arguments objectAtIndex:0];
|
|
|
154 |
|
|
|
155 |
self.styleDark = [value boolValue];
|
|
|
156 |
}
|
|
|
157 |
*/
|
|
|
158 |
|
|
|
159 |
@end
|
|
|
160 |
|