@zenkit-dev/cordova-plugin-wkwebview-inputfocusfix 1.0.5-dev.0

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 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-dev.0",
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,12 @@
1
+ #import <Foundation/Foundation.h>
2
+ #import <Cordova/CDVPlugin.h>
3
+ #import <WebKit/WebKit.h>
4
+
5
+ NS_ASSUME_NONNULL_BEGIN
6
+
7
+ @interface WKWebViewInputFocusFix : CDVPlugin<WKScriptMessageHandler, NSURLSessionDelegate>
8
+ - (void) keyboardDisplayDoesNotRequireUserAction;
9
+
10
+ @end
11
+
12
+ NS_ASSUME_NONNULL_END
@@ -0,0 +1,59 @@
1
+ #import <objc/runtime.h>
2
+ #import "CDVWKWebViewEngine+InputFocusFix.h"
3
+ #import <Cordova/CDV.h>
4
+
5
+ NS_ASSUME_NONNULL_BEGIN
6
+
7
+ @implementation WKWebViewInputFocusFix
8
+
9
+ -(void) pluginInitialize {
10
+ [super pluginInitialize];
11
+
12
+ if (![self.webView isKindOfClass:WKWebView.class])
13
+ return;
14
+
15
+ [self keyboardDisplayDoesNotRequireUserAction];
16
+ }
17
+
18
+ // https://github.com/Telerik-Verified-Plugins/WKWebView/commit/04e8296adeb61f289f9c698045c19b62d080c7e3
19
+ // https://stackoverflow.com/a/48623286/3297914
20
+ - (void) keyboardDisplayDoesNotRequireUserAction {
21
+ Class class = NSClassFromString(@"WKContentView");
22
+ NSOperatingSystemVersion iOS_11_3_0 = (NSOperatingSystemVersion){11, 3, 0};
23
+ NSOperatingSystemVersion iOS_12_2_0 = (NSOperatingSystemVersion){12, 2, 0};
24
+ NSOperatingSystemVersion iOS_13_0_0 = (NSOperatingSystemVersion){13, 0, 0};
25
+ NSOperatingSystemVersion iOS_14_0_0 = (NSOperatingSystemVersion){14, 0, 0};
26
+ NSOperatingSystemVersion iOS_15_0_0 = (NSOperatingSystemVersion){15, 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_15_0_0]) {
31
+ methodSignature = "_elementDidFocus:userIsInteracting:blurPreviousNode:activityStateChanges:userObject:";
32
+ } else if ([[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion: iOS_14_0_0]) {
33
+ methodSignature = "_elementDidFocus:userIsInteracting:blurPreviousNode:activityStateChanges:userObject:";
34
+ } else if ([[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion: iOS_13_0_0]) {
35
+ methodSignature = "_elementDidFocus:userIsInteracting:blurPreviousNode:activityStateChanges:userObject:";
36
+ } else if ([[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion: iOS_12_2_0]) {
37
+ methodSignature = "_elementDidFocus:userIsInteracting:blurPreviousNode:changingActivityState:userObject:";
38
+ }
39
+
40
+ SEL selector = sel_getUid(methodSignature);
41
+ Method method = class_getInstanceMethod(class, selector);
42
+ IMP original = method_getImplementation(method);
43
+ IMP override = imp_implementationWithBlock(^void(id me, void* arg0, BOOL arg1, BOOL arg2, BOOL arg3, id arg4) {
44
+ ((void (*)(id, SEL, void*, BOOL, BOOL, BOOL, id))original)(me, selector, arg0, TRUE, arg2, arg3, arg4);
45
+ });
46
+ method_setImplementation(method, override);
47
+ } else {
48
+ SEL selector = sel_getUid("_startAssistingNode:userIsInteracting:blurPreviousNode:userObject:");
49
+ Method method = class_getInstanceMethod(class, selector);
50
+ IMP original = method_getImplementation(method);
51
+ IMP override = imp_implementationWithBlock(^void(id me, void* arg0, BOOL arg1, BOOL arg2, id arg3) {
52
+ ((void (*)(id, SEL, void*, BOOL, BOOL, id))original)(me, selector, arg0, TRUE, arg2, arg3);
53
+ });
54
+ method_setImplementation(method, override);
55
+ }
56
+ }
57
+ @end
58
+
59
+ NS_ASSUME_NONNULL_END