From 8f46ac01fadf2f4e5961115b5c49628913035ca4 Mon Sep 17 00:00:00 2001 From: Hirbod Date: Sat, 31 Mar 2018 21:11:40 +0200 Subject: [PATCH 1/3] Fix for iOS 11.3 Added fix for iOS 11.3, tested from iOS 10 to 11.3 --- src/ios/CDVWKWebViewEngine+InputFocusFix.m | 31 +++++++++++++++------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/ios/CDVWKWebViewEngine+InputFocusFix.m b/src/ios/CDVWKWebViewEngine+InputFocusFix.m index 185ac74..7dc7e34 100644 --- a/src/ios/CDVWKWebViewEngine+InputFocusFix.m +++ b/src/ios/CDVWKWebViewEngine+InputFocusFix.m @@ -1,4 +1,5 @@ #import "CDVWKWebViewEngine+InputFocusFix.h" +#import @implementation CDVWKWebViewEngine (InputFocusFix) + (void) load { @@ -18,13 +19,25 @@ - (void) swizzleWKContentViewForInputFocus { // https://github.com/Telerik-Verified-Plugins/WKWebView/commit/04e8296adeb61f289f9c698045c19b62d080c7e3 - (void) keyboardDisplayDoesNotRequireUserAction { - SEL sel = sel_getUid("_startAssistingNode:userIsInteracting:blurPreviousNode:userObject:"); - Class WKContentView = NSClassFromString(@"WKContentView"); - Method method = class_getInstanceMethod(WKContentView, sel); - IMP originalImp = method_getImplementation(method); - IMP imp = imp_implementationWithBlock(^void(id me, void* arg0, BOOL arg1, BOOL arg2, id arg3) { - ((void (*)(id, SEL, void*, BOOL, BOOL, id))originalImp)(me, sel, arg0, TRUE, arg2, arg3); - }); - method_setImplementation(method, imp); + Class class = NSClassFromString(@"WKContentView"); + NSOperatingSystemVersion iOS_11_3_0 = (NSOperatingSystemVersion){11, 3, 0}; + + if ([[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion: iOS_11_3_0]) { + SEL selector = sel_getUid("_startAssistingNode:userIsInteracting:blurPreviousNode:changingActivityState:userObject:"); + Method method = class_getInstanceMethod(class, selector); + IMP original = method_getImplementation(method); + IMP override = imp_implementationWithBlock(^void(id me, void* arg0, BOOL arg1, BOOL arg2, BOOL arg3, id arg4) { + ((void (*)(id, SEL, void*, BOOL, BOOL, BOOL, id))original)(me, selector, arg0, TRUE, arg2, arg3, arg4); + }); + method_setImplementation(method, override); + } else { + SEL selector = sel_getUid("_startAssistingNode:userIsInteracting:blurPreviousNode:userObject:"); + Method method = class_getInstanceMethod(class, selector); + IMP original = method_getImplementation(method); + IMP override = imp_implementationWithBlock(^void(id me, void* arg0, BOOL arg1, BOOL arg2, id arg3) { + ((void (*)(id, SEL, void*, BOOL, BOOL, id))original)(me, selector, arg0, TRUE, arg2, arg3); + }); + method_setImplementation(method, override); + } } -@end \ No newline at end of file +@end From bc73e73a18b0e618d548835e1633f654072a4309 Mon Sep 17 00:00:00 2001 From: Hirbod Date: Sat, 31 Mar 2018 21:17:13 +0200 Subject: [PATCH 2/3] Update CDVWKWebViewEngine+InputFocusFix.m added credits --- src/ios/CDVWKWebViewEngine+InputFocusFix.m | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ios/CDVWKWebViewEngine+InputFocusFix.m b/src/ios/CDVWKWebViewEngine+InputFocusFix.m index 7dc7e34..b82e5fa 100644 --- a/src/ios/CDVWKWebViewEngine+InputFocusFix.m +++ b/src/ios/CDVWKWebViewEngine+InputFocusFix.m @@ -18,6 +18,7 @@ - (void) swizzleWKContentViewForInputFocus { } // https://github.com/Telerik-Verified-Plugins/WKWebView/commit/04e8296adeb61f289f9c698045c19b62d080c7e3 +// https://stackoverflow.com/a/48623286/3297914 - (void) keyboardDisplayDoesNotRequireUserAction { Class class = NSClassFromString(@"WKContentView"); NSOperatingSystemVersion iOS_11_3_0 = (NSOperatingSystemVersion){11, 3, 0}; From 266747c591bcc3fbbf4b901e319ee5177c1ebec3 Mon Sep 17 00:00:00 2001 From: Hirbod Date: Sat, 31 Mar 2018 21:27:49 +0200 Subject: [PATCH 3/3] bumped version Fixed for iOS 11.3 --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 270053c..94f170e 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "url": "git+https://github.com/onderceylan/cordova-plugin-wkwebview-inputfocusfix" }, "name": "cordova-plugin-wkwebview-inputfocusfix", - "version": "1.0.1", + "version": "1.0.2", "description": "Cordova plugin for fixing auto focus issue of html elements on WKWebView", "cordova": { "id": "cordova-plugin-wkwebview-inputfocusfix", @@ -32,4 +32,4 @@ } } } -} \ No newline at end of file +}