@zenkit-dev/cordova-plugin-keyboard 1.3.0-dev.0 → 1.3.0-dev.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -2
- package/plugin.xml +9 -8
- package/src/ios/CDVKeyboard.h +19 -0
- package/src/ios/CDVKeyboard.m +81 -47
- package/www/keyboard.js +21 -0
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zenkit-dev/cordova-plugin-keyboard",
|
|
3
|
-
"version": "1.3.0-dev.
|
|
3
|
+
"version": "1.3.0-dev.2",
|
|
4
4
|
"description": "Cordova Keyboard Plugin",
|
|
5
5
|
"cordova": {
|
|
6
6
|
"id": "cordova-plugin-keyboard",
|
|
7
7
|
"platforms": [
|
|
8
|
-
"ios"
|
|
8
|
+
"ios",
|
|
9
|
+
"android"
|
|
9
10
|
]
|
|
10
11
|
},
|
|
11
12
|
"repository": "https://github.com/zenkit/cordova-plugin-keyboard.git",
|
package/plugin.xml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
|
|
3
|
+
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" id="cordova-plugin-keyboard" version="1.3.0-dev.2">
|
|
4
4
|
<name>Keyboard</name>
|
|
5
5
|
<description>Cordova Keyboard Plugin</description>
|
|
6
6
|
<license>Apache 2.0</license>
|
|
@@ -11,10 +11,11 @@
|
|
|
11
11
|
</engines>
|
|
12
12
|
|
|
13
13
|
<js-module src="www/keyboard.js" name="keyboard">
|
|
14
|
-
|
|
14
|
+
<clobbers target="window.Keyboard" />
|
|
15
15
|
<clobbers target="cordova.plugins.Keyboard" />
|
|
16
16
|
</js-module>
|
|
17
17
|
|
|
18
|
+
<!-- ios -->
|
|
18
19
|
<platform name="ios">
|
|
19
20
|
<config-file target="config.xml" parent="/*">
|
|
20
21
|
<feature name="Keyboard">
|
|
@@ -26,16 +27,16 @@
|
|
|
26
27
|
<source-file src="src/ios/CDVKeyboard.m" />
|
|
27
28
|
</platform>
|
|
28
29
|
|
|
30
|
+
<!-- android -->
|
|
29
31
|
<platform name="android">
|
|
30
32
|
<config-file target="config.xml" parent="/*">
|
|
31
33
|
<feature name="Keyboard">
|
|
32
|
-
<param name="android-package"
|
|
33
|
-
value="org.apache.cordova.labs.keyboard.KeyboardPlugin" />
|
|
34
|
+
<param name="android-package" value="org.apache.cordova.labs.keyboard.KeyboardPlugin" />
|
|
34
35
|
<param name="onload" value="true" />
|
|
35
36
|
</feature>
|
|
36
37
|
</config-file>
|
|
37
38
|
|
|
38
|
-
<source-file src="src/android/KeyboardPlugin.java"
|
|
39
|
-
target-dir="src/org/apache/cordova/labs/keyboard" />
|
|
39
|
+
<source-file src="src/android/KeyboardPlugin.java" target-dir="src/org/apache/cordova/labs/keyboard" />
|
|
40
40
|
</platform>
|
|
41
|
+
|
|
41
42
|
</plugin>
|
package/src/ios/CDVKeyboard.h
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
or more contributor license agreements. See the NOTICE file
|
|
4
|
+
distributed with this work for additional information
|
|
5
|
+
regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
to you under the Apache License, Version 2.0 (the
|
|
7
|
+
"License"); you may not use this file except in compliance
|
|
8
|
+
with the License. You may obtain a copy of the License at
|
|
9
|
+
|
|
10
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
|
|
12
|
+
Unless required by applicable law or agreed to in writing,
|
|
13
|
+
software distributed under the License is distributed on an
|
|
14
|
+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
KIND, either express or implied. See the License for the
|
|
16
|
+
specific language governing permissions and limitations
|
|
17
|
+
under the License.
|
|
18
|
+
*/
|
|
19
|
+
|
|
1
20
|
#import <Cordova/CDVPlugin.h>
|
|
2
21
|
|
|
3
22
|
@interface CDVKeyboard : CDVPlugin
|
package/src/ios/CDVKeyboard.m
CHANGED
|
@@ -1,9 +1,37 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
or more contributor license agreements. See the NOTICE file
|
|
4
|
+
distributed with this work for additional information
|
|
5
|
+
regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
to you under the Apache License, Version 2.0 (the
|
|
7
|
+
"License"); you may not use this file except in compliance
|
|
8
|
+
with the License. You may obtain a copy of the License at
|
|
9
|
+
|
|
10
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
|
|
12
|
+
Unless required by applicable law or agreed to in writing,
|
|
13
|
+
software distributed under the License is distributed on an
|
|
14
|
+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
KIND, either express or implied. See the License for the
|
|
16
|
+
specific language governing permissions and limitations
|
|
17
|
+
under the License.
|
|
18
|
+
*/
|
|
19
|
+
|
|
1
20
|
#import "CDVKeyboard.h"
|
|
21
|
+
#import <UIKit/UIKit.h>
|
|
22
|
+
#import <WebKit/WebKit.h>
|
|
2
23
|
#import <Cordova/CDVAvailability.h>
|
|
24
|
+
#if __has_include(<Cordova/CDVSettingsDictionary.h>)
|
|
25
|
+
#import <Cordova/CDVSettingsDictionary.h>
|
|
26
|
+
#else
|
|
3
27
|
#import <Cordova/NSDictionary+CordovaPreferences.h>
|
|
28
|
+
#endif
|
|
4
29
|
#import <objc/runtime.h>
|
|
5
30
|
|
|
6
|
-
|
|
31
|
+
static NSString *const WKClassString = @"WKContentView";
|
|
32
|
+
static NSString *const UITraitsClassString = @"UITextInputTraits";
|
|
33
|
+
|
|
34
|
+
@interface CDVKeyboard ()
|
|
7
35
|
|
|
8
36
|
@property(nonatomic, readwrite, assign) BOOL keyboardIsVisible;
|
|
9
37
|
@property(readwrite, assign, nonatomic) BOOL keyboardShrinksView;
|
|
@@ -20,29 +48,24 @@
|
|
|
20
48
|
NSString *js = [NSString stringWithFormat:@"cordova.fireWindowEvent('%@')", event];
|
|
21
49
|
// Don't schedule the js in the run loop so the the window event handler can handle the events
|
|
22
50
|
// as soon as possible.
|
|
23
|
-
[self.commandDelegate evalJs:js scheduledOnRunLoop:
|
|
51
|
+
[self.commandDelegate evalJs:js scheduledOnRunLoop:NO];
|
|
24
52
|
}
|
|
25
53
|
|
|
26
54
|
#pragma mark Initialize
|
|
27
55
|
|
|
28
|
-
NSString *WKClassString;
|
|
29
|
-
NSString *UITraitsClassString;
|
|
30
|
-
|
|
31
56
|
- (void)pluginInitialize {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
NSDictionary *settings = self.commandDelegate.settings;
|
|
57
|
+
// CDVSettingsDictionary on cordova-ios 8+, NSDictionary before
|
|
58
|
+
__auto_type settings = self.commandDelegate.settings;
|
|
36
59
|
|
|
37
60
|
self.keyboardShrinksView = [settings cordovaBoolSettingForKey:@"KeyboardShrinksView"
|
|
38
61
|
defaultValue:YES];
|
|
39
62
|
|
|
40
|
-
|
|
41
|
-
|
|
63
|
+
BOOL hide = [settings cordovaBoolSettingForKey:@"HideKeyboardFormAccessoryBar"
|
|
64
|
+
defaultValue:YES];
|
|
42
65
|
[self setHideFormAccessoryBar:hide];
|
|
43
66
|
|
|
44
|
-
|
|
45
|
-
|
|
67
|
+
BOOL disabled = [settings cordovaBoolSettingForKey:@"KeyboardDisablesScrolling"
|
|
68
|
+
defaultValue:YES];
|
|
46
69
|
[self setKeyboardDisablesScrolling:disabled];
|
|
47
70
|
|
|
48
71
|
NSString *keyboardStyle = [settings cordovaSettingForKey:@"KeyboardStyle"];
|
|
@@ -125,6 +148,8 @@ NSString *UITraitsClassString;
|
|
|
125
148
|
IMP appearanceImpl = imp_implementationWithBlock(^(id _s) {
|
|
126
149
|
return keyboardAppearance;
|
|
127
150
|
});
|
|
151
|
+
char types[16];
|
|
152
|
+
snprintf(types, sizeof(types), "%s@:", @encode(UIKeyboardAppearance));
|
|
128
153
|
|
|
129
154
|
for (NSString *classString in @[ WKClassString, UITraitsClassString ]) {
|
|
130
155
|
Class class = NSClassFromString(classString);
|
|
@@ -134,7 +159,7 @@ NSString *UITraitsClassString;
|
|
|
134
159
|
if (method != NULL) {
|
|
135
160
|
method_setImplementation(method, appearanceImpl);
|
|
136
161
|
} else {
|
|
137
|
-
class_addMethod(class, selector, appearanceImpl,
|
|
162
|
+
class_addMethod(class, selector, appearanceImpl, types);
|
|
138
163
|
}
|
|
139
164
|
}
|
|
140
165
|
|
|
@@ -162,14 +187,17 @@ static IMP WKOriginalImp;
|
|
|
162
187
|
class_getInstanceMethod(NSClassFromString(WKClassString), @selector(inputAccessoryView));
|
|
163
188
|
|
|
164
189
|
if (hideFormAccessoryBar) {
|
|
165
|
-
|
|
190
|
+
// The swizzle is process-wide, so only remember the real implementation once.
|
|
191
|
+
if (WKOriginalImp == NULL) {
|
|
192
|
+
WKOriginalImp = method_getImplementation(WKMethod);
|
|
193
|
+
}
|
|
166
194
|
|
|
167
195
|
IMP hideFormAccessoryBarImpl = imp_implementationWithBlock(^(id _s) {
|
|
168
196
|
return nil;
|
|
169
197
|
});
|
|
170
198
|
|
|
171
199
|
method_setImplementation(WKMethod, hideFormAccessoryBarImpl);
|
|
172
|
-
} else {
|
|
200
|
+
} else if (WKOriginalImp != NULL) {
|
|
173
201
|
method_setImplementation(WKMethod, WKOriginalImp);
|
|
174
202
|
}
|
|
175
203
|
|
|
@@ -181,33 +209,36 @@ static IMP WKOriginalImp;
|
|
|
181
209
|
- (CGFloat)calculateFrameHeight:(NSNotification *)notification {
|
|
182
210
|
UIScreen *screen = self.webView.window.screen;
|
|
183
211
|
CGFloat superviewFrameHeight = self.webView.superview.frame.size.height;
|
|
212
|
+
if (screen == nil) {
|
|
213
|
+
return superviewFrameHeight;
|
|
214
|
+
}
|
|
215
|
+
|
|
184
216
|
CGRect keyboardEndFrame =
|
|
185
217
|
[[notification.userInfo valueForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
|
|
186
218
|
|
|
187
219
|
// NOTE: Detect if the keyboard is attached or floating.
|
|
188
|
-
// If the keyboard is floating
|
|
220
|
+
// If the keyboard is floating its frame should not match the screen bounds.
|
|
189
221
|
BOOL keyboardAttached = screen.bounds.origin.x == keyboardEndFrame.origin.x &&
|
|
190
222
|
screen.bounds.size.width == keyboardEndFrame.size.width;
|
|
191
223
|
|
|
192
224
|
// NOTE: If the keyboard is floating (not attached) we reset the view height.
|
|
193
|
-
if (keyboardAttached
|
|
225
|
+
if (!keyboardAttached) {
|
|
194
226
|
return superviewFrameHeight;
|
|
195
227
|
}
|
|
196
228
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
toCoordinateSpace:screen.coordinateSpace];
|
|
200
|
-
|
|
201
|
-
// NOTE: We set the web view height to the y position of keyboard,
|
|
202
|
-
// this should prevent an error in the calculation beeing carried over.
|
|
229
|
+
// NOTE: We set the web view height to the y position of the keyboard,
|
|
230
|
+
// this should prevent an error in the calculation being carried over.
|
|
203
231
|
// (e.g. the view could already be changed because we call this with a delay)
|
|
204
|
-
//
|
|
205
|
-
//
|
|
206
|
-
|
|
232
|
+
// The keyboard frame is in screen coordinates, so we convert it to the web view
|
|
233
|
+
// to account for the view position on the screen.
|
|
234
|
+
// (e.g. the statusbar or the "Slide Over" multitask mode on iPads)
|
|
235
|
+
CGRect keyboardFrame = [self.webView convertRect:keyboardEndFrame
|
|
236
|
+
fromCoordinateSpace:screen.coordinateSpace];
|
|
237
|
+
CGFloat relativeKeyboardY = CGRectGetMinY(keyboardFrame);
|
|
207
238
|
|
|
208
239
|
// NOTE: We don't allow the frame height to be smaller than 0 or bigger than the superview.
|
|
209
|
-
// If this happened we
|
|
210
|
-
// in that case it is
|
|
240
|
+
// If this happened we probably calculated something wrong,
|
|
241
|
+
// in that case it is probably better to reset the height.
|
|
211
242
|
if (relativeKeyboardY <= 0 || relativeKeyboardY > superviewFrameHeight) {
|
|
212
243
|
return superviewFrameHeight;
|
|
213
244
|
}
|
|
@@ -220,23 +251,30 @@ static IMP WKOriginalImp;
|
|
|
220
251
|
if (frame.size.height == frameHeight) {
|
|
221
252
|
return;
|
|
222
253
|
}
|
|
254
|
+
frame.size.height = frameHeight;
|
|
223
255
|
|
|
224
256
|
double duration =
|
|
225
257
|
[[notification.userInfo valueForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
|
|
226
258
|
UIViewAnimationCurve curve =
|
|
227
259
|
[[notification.userInfo valueForKey:UIKeyboardAnimationCurveUserInfoKey] integerValue];
|
|
228
260
|
|
|
229
|
-
[UIView
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
261
|
+
[UIView animateWithDuration:duration
|
|
262
|
+
delay:0
|
|
263
|
+
options:(UIViewAnimationOptions)curve << 16 | UIViewAnimationOptionAllowUserInteraction
|
|
264
|
+
animations:^{
|
|
265
|
+
self.webView.frame = frame;
|
|
266
|
+
}
|
|
267
|
+
completion:nil];
|
|
235
268
|
}
|
|
236
269
|
|
|
237
270
|
#pragma mark KeyboardDisablesScrolling
|
|
238
|
-
|
|
239
|
-
|
|
271
|
+
|
|
272
|
+
// UIView's scrollView category is deprecated in cordova-ios 8
|
|
273
|
+
- (UIScrollView *)webViewScrollView {
|
|
274
|
+
if ([self.webView isKindOfClass:[WKWebView class]]) {
|
|
275
|
+
return ((WKWebView *)self.webView).scrollView;
|
|
276
|
+
}
|
|
277
|
+
return nil;
|
|
240
278
|
}
|
|
241
279
|
|
|
242
280
|
- (void)setKeyboardDisablesScrolling:(BOOL)keyboardDisablesScrolling {
|
|
@@ -244,13 +282,9 @@ static IMP WKOriginalImp;
|
|
|
244
282
|
return;
|
|
245
283
|
}
|
|
246
284
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
} else {
|
|
251
|
-
self.webView.scrollView.scrollEnabled = YES;
|
|
252
|
-
self.webView.scrollView.delegate = nil;
|
|
253
|
-
}
|
|
285
|
+
// Do not assign scrollView.delegate: CDVViewController uses it for
|
|
286
|
+
// built-in status-bar inset tracking on cordova-ios 8.
|
|
287
|
+
[self webViewScrollView].scrollEnabled = !keyboardDisablesScrolling;
|
|
254
288
|
|
|
255
289
|
_keyboardDisablesScrolling = keyboardDisablesScrolling;
|
|
256
290
|
}
|
|
@@ -273,7 +307,7 @@ static IMP WKOriginalImp;
|
|
|
273
307
|
}
|
|
274
308
|
|
|
275
309
|
- (void)keyboardDisablesScrolling:(CDVInvokedUrlCommand *)command {
|
|
276
|
-
|
|
310
|
+
BOOL disabled = self.keyboardDisablesScrolling;
|
|
277
311
|
if (command.arguments.count > 0) {
|
|
278
312
|
id value = [command.arguments objectAtIndex:0];
|
|
279
313
|
if (!([value isKindOfClass:[NSNumber class]])) {
|
|
@@ -291,7 +325,7 @@ static IMP WKOriginalImp;
|
|
|
291
325
|
}
|
|
292
326
|
|
|
293
327
|
- (void)hideFormAccessoryBar:(CDVInvokedUrlCommand *)command {
|
|
294
|
-
|
|
328
|
+
BOOL hide = self.hideFormAccessoryBar;
|
|
295
329
|
if (command.arguments.count > 0) {
|
|
296
330
|
id value = [command.arguments objectAtIndex:0];
|
|
297
331
|
if (!([value isKindOfClass:[NSNumber class]])) {
|
|
@@ -317,7 +351,7 @@ static IMP WKOriginalImp;
|
|
|
317
351
|
|
|
318
352
|
- (void)setKeyboardStyle:(CDVInvokedUrlCommand *)command {
|
|
319
353
|
NSString *style = @"light";
|
|
320
|
-
id value = [command
|
|
354
|
+
id value = [command argumentAtIndex:0];
|
|
321
355
|
if ([value isKindOfClass:[NSString class]]) {
|
|
322
356
|
style = (NSString *)value;
|
|
323
357
|
}
|
package/www/keyboard.js
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
/*
|
|
2
|
+
*
|
|
3
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
4
|
+
* or more contributor license agreements. See the NOTICE file
|
|
5
|
+
* distributed with this work for additional information
|
|
6
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
7
|
+
* to you under the Apache License, Version 2.0 (the
|
|
8
|
+
* "License"); you may not use this file except in compliance
|
|
9
|
+
* with the License. You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing,
|
|
14
|
+
* software distributed under the License is distributed on an
|
|
15
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
16
|
+
* KIND, either express or implied. See the License for the
|
|
17
|
+
* specific language governing permissions and limitations
|
|
18
|
+
* under the License.
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
|
|
1
22
|
var cordova = require('cordova');
|
|
2
23
|
var exec = require('cordova/exec');
|
|
3
24
|
|