@zenkit-dev/cordova-plugin-wkwebview-inputfocusfix 1.0.5
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/LICENSE +21 -0
- package/README.md +19 -0
- package/package.json +23 -0
- package/plugin.xml +26 -0
- package/src/ios/CDVWKWebViewEngine+InputFocusFix.h +9 -0
- package/src/ios/CDVWKWebViewEngine+InputFocusFix.m +53 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Zenkit
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# CDVWKWebViewEngine InputFocusFix
|
|
2
|
+
|
|
3
|
+
> Cordova plugin for fixing auto focus issue of html elements on WKWebView
|
|
4
|
+
|
|
5
|
+
This plugin adds support for the `KeyboardDisplayRequiresUserAction` setting when using the `CDVWKWebViewEngine`, by swizzling of the `WKContentView`.
|
|
6
|
+
_This plugin works for iOS 13.0, 12.2, 11.x and 10.x_
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
Install the plugin by running:
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
cordova plugin add github:zenkit/cordova-plugin-wkwebview-inputfocusfix#v1.0.5
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Why the fork?
|
|
17
|
+
|
|
18
|
+
The [original plugin](https://github.com/onderceylan/cordova-plugin-wkwebview-inputfocusfix) was archived because it shouldn't be needed anymore.
|
|
19
|
+
But this seems only to be true when using the `cordova-plugin-ionic-webview` and it is still needed when using the `cordova-plugin-wkwebview-engine` because it will not be [fixed](https://issues.apache.org/jira/browse/CB-12037?focusedCommentId=16538144&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-16538144).
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zenkit-dev/cordova-plugin-wkwebview-inputfocusfix",
|
|
3
|
+
"description": "Cordova plugin for fixing auto focus issue of html elements on WKWebView",
|
|
4
|
+
"version": "1.0.5",
|
|
5
|
+
"author": "Zenkit <info@zenkit.com>",
|
|
6
|
+
"repository": "https://github.com/zenkit/cordova-plugin-wkwebview-inputfocusfix.git",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"cordova": {
|
|
9
|
+
"id": "cordova-plugin-wkwebview-inputfocusfix",
|
|
10
|
+
"platforms": [
|
|
11
|
+
"ios"
|
|
12
|
+
]
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"ecosystem:cordova",
|
|
16
|
+
"cordova-ios",
|
|
17
|
+
"input",
|
|
18
|
+
"focus",
|
|
19
|
+
"auto-focus",
|
|
20
|
+
"wkwebview",
|
|
21
|
+
"ionic"
|
|
22
|
+
]
|
|
23
|
+
}
|
package/plugin.xml
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<?xml version='1.0' encoding='utf-8'?>
|
|
2
|
+
<plugin id="cordova-plugin-wkwebview-inputfocusfix"
|
|
3
|
+
version="1.0.5"
|
|
4
|
+
xmlns="http://cordova.apache.org/ns/plugins/1.0"
|
|
5
|
+
xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
|
6
|
+
xmlns:rim="http://www.blackberry.com/ns/widgets"
|
|
7
|
+
xmlns:android="http://schemas.android.com/apk/res/android">
|
|
8
|
+
<name>WKWebView Input Focus Fix</name>
|
|
9
|
+
<license>MIT</license>
|
|
10
|
+
|
|
11
|
+
<engines>
|
|
12
|
+
<engine name="cordova" version=">=3.2.0" />
|
|
13
|
+
</engines>
|
|
14
|
+
|
|
15
|
+
<platform name="ios">
|
|
16
|
+
<config-file parent="/*" target="config.xml">
|
|
17
|
+
<feature name="WKWebViewInputFocusFix">
|
|
18
|
+
<param name="ios-package" value="WKWebViewInputFocusFix" />
|
|
19
|
+
<param name="onload" value="true" />
|
|
20
|
+
</feature>
|
|
21
|
+
</config-file>
|
|
22
|
+
|
|
23
|
+
<header-file src="src/ios/CDVWKWebViewEngine+InputFocusFix.h" />
|
|
24
|
+
<source-file src="src/ios/CDVWKWebViewEngine+InputFocusFix.m" />
|
|
25
|
+
</platform>
|
|
26
|
+
</plugin>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
#import <objc/runtime.h>
|
|
2
|
+
#import <Cordova/NSDictionary+CordovaPreferences.h>
|
|
3
|
+
#import "CDVWKWebViewEngine.h"
|
|
4
|
+
|
|
5
|
+
@interface CDVWKWebViewEngine (InputFocusFix)
|
|
6
|
+
+ (void) load;
|
|
7
|
+
- (void) swizzleWKContentViewForInputFocus;
|
|
8
|
+
- (void) keyboardDisplayDoesNotRequireUserAction;
|
|
9
|
+
@end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
#import "CDVWKWebViewEngine+InputFocusFix.h"
|
|
2
|
+
#import <objc/runtime.h>
|
|
3
|
+
|
|
4
|
+
@implementation CDVWKWebViewEngine (InputFocusFix)
|
|
5
|
+
+ (void) load {
|
|
6
|
+
static dispatch_once_t onceToken;
|
|
7
|
+
dispatch_once(&onceToken, ^{
|
|
8
|
+
CDVWKWebViewEngine *cdvWKWebViewEngine = [[CDVWKWebViewEngine alloc] init];
|
|
9
|
+
[cdvWKWebViewEngine swizzleWKContentViewForInputFocus];
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
- (void) swizzleWKContentViewForInputFocus {
|
|
14
|
+
NSDictionary* settings = self.commandDelegate.settings;
|
|
15
|
+
if (![settings cordovaBoolSettingForKey:@"KeyboardDisplayRequiresUserAction" defaultValue:YES]) {
|
|
16
|
+
[self keyboardDisplayDoesNotRequireUserAction];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// https://github.com/Telerik-Verified-Plugins/WKWebView/commit/04e8296adeb61f289f9c698045c19b62d080c7e3
|
|
21
|
+
// https://stackoverflow.com/a/48623286/3297914
|
|
22
|
+
- (void) keyboardDisplayDoesNotRequireUserAction {
|
|
23
|
+
Class class = NSClassFromString(@"WKContentView");
|
|
24
|
+
NSOperatingSystemVersion iOS_11_3_0 = (NSOperatingSystemVersion){11, 3, 0};
|
|
25
|
+
NSOperatingSystemVersion iOS_12_2_0 = (NSOperatingSystemVersion){12, 2, 0};
|
|
26
|
+
NSOperatingSystemVersion iOS_13_0_0 = (NSOperatingSystemVersion){13, 0, 0};
|
|
27
|
+
|
|
28
|
+
if ([[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion: iOS_11_3_0]) {
|
|
29
|
+
char* methodSignature = "_startAssistingNode:userIsInteracting:blurPreviousNode:changingActivityState:userObject:";
|
|
30
|
+
if ([[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion: iOS_13_0_0]) {
|
|
31
|
+
methodSignature = "_elementDidFocus:userIsInteracting:blurPreviousNode:activityStateChanges:userObject:";
|
|
32
|
+
} else if ([[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion: iOS_12_2_0]) {
|
|
33
|
+
methodSignature = "_elementDidFocus:userIsInteracting:blurPreviousNode:changingActivityState:userObject:";
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
SEL selector = sel_getUid(methodSignature);
|
|
37
|
+
Method method = class_getInstanceMethod(class, selector);
|
|
38
|
+
IMP original = method_getImplementation(method);
|
|
39
|
+
IMP override = imp_implementationWithBlock(^void(id me, void* arg0, BOOL arg1, BOOL arg2, BOOL arg3, id arg4) {
|
|
40
|
+
((void (*)(id, SEL, void*, BOOL, BOOL, BOOL, id))original)(me, selector, arg0, TRUE, arg2, arg3, arg4);
|
|
41
|
+
});
|
|
42
|
+
method_setImplementation(method, override);
|
|
43
|
+
} else {
|
|
44
|
+
SEL selector = sel_getUid("_startAssistingNode:userIsInteracting:blurPreviousNode:userObject:");
|
|
45
|
+
Method method = class_getInstanceMethod(class, selector);
|
|
46
|
+
IMP original = method_getImplementation(method);
|
|
47
|
+
IMP override = imp_implementationWithBlock(^void(id me, void* arg0, BOOL arg1, BOOL arg2, id arg3) {
|
|
48
|
+
((void (*)(id, SEL, void*, BOOL, BOOL, id))original)(me, selector, arg0, TRUE, arg2, arg3);
|
|
49
|
+
});
|
|
50
|
+
method_setImplementation(method, override);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
@end
|