@moodlehq/cordova-plugin-ionic-keyboard 2.2.0-moodle.2 → 2.2.0-moodle.4
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/README.md +2 -1
- package/package.json +1 -1
- package/plugin.xml +1 -1
- package/src/ios/CDVIonicKeyboard.m +99 -13
package/README.md
CHANGED
|
@@ -11,6 +11,7 @@ We created this fork because we needed to include the following modifications in
|
|
|
11
11
|
| [#883](https://github.com/ionic-team/cordova-plugin-ionic-keyboard/pull/181) | Fix ion-footer hidden behind keyboard on iOS |
|
|
12
12
|
| - | Port Android implementation from Capacitor plugin |
|
|
13
13
|
| - | Set a CSS variable with the height of the keyboard on iOS |
|
|
14
|
+
| - | Update code for Cordova iOS 8 |
|
|
14
15
|
|
|
15
16
|
You can see all the changes here: [master...moodlemobile:master](https://github.com/ionic-team/cordova-plugin-ionic-keyboard/compare/master...moodlemobile:master)
|
|
16
17
|
|
|
@@ -19,5 +20,5 @@ You can see all the changes here: [master...moodlemobile:master](https://github.
|
|
|
19
20
|
You can install this package using the [original installation instructions](https://github.com/ionic-team/cordova-plugin-ionic-keyboard#installation), but installing this package instead:
|
|
20
21
|
|
|
21
22
|
```sh
|
|
22
|
-
cordova plugin add @moodlehq/cordova-plugin-ionic-keyboard@2.2.0-moodle.
|
|
23
|
+
cordova plugin add @moodlehq/cordova-plugin-ionic-keyboard@2.2.0-moodle.4
|
|
23
24
|
```
|
package/package.json
CHANGED
package/plugin.xml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
2
|
|
|
3
|
-
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:rim="http://www.blackberry.com/ns/widgets" xmlns:android="http://schemas.android.com/apk/res/android" id="@moodlehq/cordova-plugin-ionic-keyboard" version="2.2.0-moodle.
|
|
3
|
+
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:rim="http://www.blackberry.com/ns/widgets" xmlns:android="http://schemas.android.com/apk/res/android" id="@moodlehq/cordova-plugin-ionic-keyboard" version="2.2.0-moodle.4">
|
|
4
4
|
<name>cordova-plugin-ionic-keyboard</name>
|
|
5
5
|
<description>Ionic Keyboard Plugin</description>
|
|
6
6
|
<license>Apache 2.0</license>
|
|
@@ -18,8 +18,10 @@
|
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
20
|
#import "CDVIonicKeyboard.h"
|
|
21
|
+
#import <Foundation/Foundation.h>
|
|
22
|
+
#import <UIKit/UIKit.h>
|
|
21
23
|
#import <Cordova/CDVAvailability.h>
|
|
22
|
-
#import <Cordova/
|
|
24
|
+
#import <Cordova/CDVSettingsDictionary.h>
|
|
23
25
|
#import <objc/runtime.h>
|
|
24
26
|
|
|
25
27
|
typedef enum : NSUInteger {
|
|
@@ -66,7 +68,7 @@ NSString* UITraitsClassString;
|
|
|
66
68
|
WKClassString = [@[@"WK", @"Content", @"View"] componentsJoinedByString:@""];
|
|
67
69
|
UITraitsClassString = [@[@"UI", @"Text", @"Input", @"Traits"] componentsJoinedByString:@""];
|
|
68
70
|
|
|
69
|
-
|
|
71
|
+
id settings = self.commandDelegate.settings;
|
|
70
72
|
|
|
71
73
|
self.disableScroll = ![settings cordovaBoolSettingForKey:@"ScrollEnabled" defaultValue:NO];
|
|
72
74
|
|
|
@@ -129,9 +131,26 @@ NSString* UITraitsClassString;
|
|
|
129
131
|
|
|
130
132
|
#pragma mark Keyboard events
|
|
131
133
|
|
|
134
|
+
- (UIScrollView *)webViewScrollView
|
|
135
|
+
{
|
|
136
|
+
SEL scrollViewSelector = NSSelectorFromString(@"scrollView");
|
|
137
|
+
if (![self.webView respondsToSelector:scrollViewSelector]) {
|
|
138
|
+
return nil;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
#pragma clang diagnostic push
|
|
142
|
+
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
|
|
143
|
+
return [self.webView performSelector:scrollViewSelector];
|
|
144
|
+
#pragma clang diagnostic pop
|
|
145
|
+
}
|
|
146
|
+
|
|
132
147
|
- (void)resetScrollView
|
|
133
148
|
{
|
|
134
|
-
UIScrollView *scrollView = [self
|
|
149
|
+
UIScrollView *scrollView = [self webViewScrollView];
|
|
150
|
+
if (scrollView == nil) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
|
|
135
154
|
[scrollView setContentInset:UIEdgeInsetsZero];
|
|
136
155
|
}
|
|
137
156
|
|
|
@@ -210,6 +229,62 @@ NSString* UITraitsClassString;
|
|
|
210
229
|
}
|
|
211
230
|
}
|
|
212
231
|
|
|
232
|
+
- (CGRect)getAvailableBounds
|
|
233
|
+
{
|
|
234
|
+
UIView *webView = self.webView;
|
|
235
|
+
// Preferred path: use the Cordova view hierarchy for the current plugin instance.
|
|
236
|
+
if (webView.superview != nil) {
|
|
237
|
+
return webView.superview.bounds;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (self.viewController != nil && self.viewController.view != nil) {
|
|
241
|
+
return self.viewController.view.bounds;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
UIWindow *window = webView.window ?: self.viewController.view.window;
|
|
245
|
+
if (window != nil) {
|
|
246
|
+
return window.bounds;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// Fallback path for early lifecycle and scene transitions where view.window can be temporarily nil.
|
|
250
|
+
if (@available(iOS 13.0, *)) {
|
|
251
|
+
for (UIScene *scene in UIApplication.sharedApplication.connectedScenes) {
|
|
252
|
+
if (![scene isKindOfClass:[UIWindowScene class]]) {
|
|
253
|
+
continue;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
UIWindowScene *windowScene = (UIWindowScene *) scene;
|
|
257
|
+
// Prefer scenes that are visible to the user. Inactive can happen during transitions.
|
|
258
|
+
if (windowScene.activationState != UISceneActivationStateForegroundActive &&
|
|
259
|
+
windowScene.activationState != UISceneActivationStateForegroundInactive) {
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
NSArray<UIWindow *> *sceneWindows = windowScene.windows;
|
|
264
|
+
for (UIWindow *sceneWindow in sceneWindows) {
|
|
265
|
+
if (sceneWindow.isKeyWindow) {
|
|
266
|
+
return sceneWindow.bounds;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
UIWindow *firstWindow = sceneWindows.firstObject;
|
|
271
|
+
if (firstWindow != nil) {
|
|
272
|
+
return firstWindow.bounds;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
id<UIApplicationDelegate> appDelegate = [UIApplication sharedApplication].delegate;
|
|
278
|
+
if ([appDelegate respondsToSelector:@selector(window)]) {
|
|
279
|
+
UIWindow *delegateWindow = appDelegate.window;
|
|
280
|
+
if (delegateWindow != nil) {
|
|
281
|
+
return delegateWindow.bounds;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
return [UIScreen mainScreen].bounds;
|
|
286
|
+
}
|
|
287
|
+
|
|
213
288
|
- (void)_updateFrame
|
|
214
289
|
{
|
|
215
290
|
CGSize statusBarSize = [[UIApplication sharedApplication] statusBarFrame].size;
|
|
@@ -221,34 +296,38 @@ NSString* UITraitsClassString;
|
|
|
221
296
|
_paddingBottom = _paddingBottom + 20;
|
|
222
297
|
}
|
|
223
298
|
NSLog(@"CDVIonicKeyboard: updating frame");
|
|
224
|
-
|
|
225
|
-
CGRect f = [[[[UIApplication sharedApplication] delegate] window] bounds];
|
|
299
|
+
CGRect f = [self getAvailableBounds];
|
|
226
300
|
CGRect wf = self.webView.frame;
|
|
301
|
+
int availableHeight = MAX(0, (int)(f.size.height - wf.origin.y));
|
|
227
302
|
switch (self.keyboardResizes) {
|
|
228
303
|
case ResizeBody:
|
|
229
304
|
{
|
|
230
305
|
NSString *js = [NSString stringWithFormat:@"Keyboard.fireOnResize(%d, %d, document.body);",
|
|
231
|
-
_paddingBottom,
|
|
306
|
+
_paddingBottom, availableHeight];
|
|
232
307
|
[self.commandDelegate evalJs:js];
|
|
233
308
|
break;
|
|
234
309
|
}
|
|
235
310
|
case ResizeIonic:
|
|
236
311
|
{
|
|
237
312
|
NSString *js = [NSString stringWithFormat:@"Keyboard.fireOnResize(%d, %d, document.querySelector('ion-app'));",
|
|
238
|
-
_paddingBottom,
|
|
313
|
+
_paddingBottom, availableHeight];
|
|
239
314
|
[self.commandDelegate evalJs:js];
|
|
240
315
|
break;
|
|
241
316
|
}
|
|
242
317
|
case ResizeNative:
|
|
243
318
|
{
|
|
244
|
-
|
|
319
|
+
CGFloat width = MAX(0.f, f.size.width - wf.origin.x);
|
|
320
|
+
CGFloat height = MAX(0.f, f.size.height - wf.origin.y - self.paddingBottom);
|
|
321
|
+
[self.webView setFrame:CGRectMake(wf.origin.x, wf.origin.y, width, height)];
|
|
245
322
|
break;
|
|
246
323
|
}
|
|
247
324
|
default:
|
|
325
|
+
{
|
|
248
326
|
NSString *js = [NSString stringWithFormat:@"Keyboard.fireOnResize(%d, %d, null);",
|
|
249
|
-
_paddingBottom,
|
|
327
|
+
_paddingBottom, availableHeight];
|
|
250
328
|
[self.commandDelegate evalJs:js];
|
|
251
329
|
break;
|
|
330
|
+
}
|
|
252
331
|
}
|
|
253
332
|
[self resetScrollView];
|
|
254
333
|
}
|
|
@@ -329,13 +408,20 @@ static IMP WKOriginalImp;
|
|
|
329
408
|
if (disableScroll == _disableScroll) {
|
|
330
409
|
return;
|
|
331
410
|
}
|
|
411
|
+
|
|
412
|
+
UIScrollView *scrollView = [self webViewScrollView];
|
|
413
|
+
if (scrollView == nil) {
|
|
414
|
+
_disableScroll = disableScroll;
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
|
|
332
418
|
if (disableScroll) {
|
|
333
|
-
|
|
334
|
-
|
|
419
|
+
scrollView.scrollEnabled = NO;
|
|
420
|
+
scrollView.delegate = self;
|
|
335
421
|
}
|
|
336
422
|
else {
|
|
337
|
-
|
|
338
|
-
|
|
423
|
+
scrollView.scrollEnabled = YES;
|
|
424
|
+
scrollView.delegate = nil;
|
|
339
425
|
}
|
|
340
426
|
_disableScroll = disableScroll;
|
|
341
427
|
}
|