diff --git a/README.md b/README.md index 4674035..6aa2a8a 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,18 @@ cordova plugin add cordova-plugin-ionic-keyboard --save <preference name="HideKeyboardFormAccessoryBar" value="false" /> ``` +### HideSuggestionBar (for iOS only) + +> Boolean (false by default) + +#### Possible values +- `true`: hides the keyboard Suggestion bar. +- `false`: shows the keyboard Suggestion bar. + +```xml +<preference name="HideSuggestionBar" value="false" /> +``` + ### resizeOnFullScreen (for Android only) There is an Android bug that prevents the keyboard from resizing the WebView when the app is in full screen (i.e. if StatusBar plugin is used to hide the StatusBar). This setting, if set to true, add a workaround that resizes the WebView even when the app is in full screen. @@ -100,6 +112,23 @@ Keyboard.hideFormAccessoryBar(false); Keyboard.hideFormAccessoryBar(null, (currentValue) => { console.log(currentValue); }); ``` +### Keyboard.hideSuggestionBar (for iOS only) + +> Hide the keyboard suggestion Bar. + +Set to true to hide the additional suggestionbar that is on top of the keyboard. This suggestionbar features the OTP, Username, and Password other autofill values. + +```js +Keyboard.hideSuggestionBar(value); +``` + +#### Quick Example + +```js +Keyboard.hideSuggestionBar(true); +Keyboard.hideSuggestionBar(false); +``` + ### Keyboard.hide > Hide the keyboard diff --git a/src/ios/CDVIonicKeyboard.m b/src/ios/CDVIonicKeyboard.m index e4615a8..8078040 100644 --- a/src/ios/CDVIonicKeyboard.m +++ b/src/ios/CDVIonicKeyboard.m @@ -37,6 +37,8 @@ @interface CDVIonicKeyboard () <UIScrollViewDelegate> @property (readwrite, assign, nonatomic) BOOL disableScroll; @property (readwrite, assign, nonatomic) BOOL hideFormAccessoryBar; +@property (readwrite, assign, nonatomic) BOOL hideSuggestionBar; +@property (readwrite, assign, nonatomic) BOOL isMethodSwizzled; @property (readwrite, assign, nonatomic) BOOL keyboardIsVisible; @property (nonatomic, readwrite) ResizePolicy keyboardResizes; @property (readwrite, assign, nonatomic) NSString* keyboardStyle; @@ -59,12 +61,16 @@ - (id)settingForKey:(NSString *)key NSString* UIClassString; NSString* WKClassString; NSString* UITraitsClassString; +NSString* SelectorString; +NSString* SuggestionClassString; - (void)pluginInitialize { UIClassString = [@[@"UI", @"Web", @"Browser", @"View"] componentsJoinedByString:@""]; WKClassString = [@[@"WK", @"Content", @"View"] componentsJoinedByString:@""]; UITraitsClassString = [@[@"UI", @"Text", @"Input", @"Traits"] componentsJoinedByString:@""]; + SelectorString = [@[@"is", @"Visible", @"For", @"Input", @"Delegate", @":", @"input", @"Views", @":"] componentsJoinedByString:@""]; + SuggestionClassString = [@[@"UI", @"Prediction", @"View", @"Controller"] componentsJoinedByString:@""]; NSDictionary *settings = self.commandDelegate.settings; @@ -90,6 +96,7 @@ - (void)pluginInitialize NSLog(@"CDVIonicKeyboard: resize mode %lu", (unsigned long)self.keyboardResizes); } self.hideFormAccessoryBar = [settings cordovaBoolSettingForKey:@"HideKeyboardFormAccessoryBar" defaultValue:YES]; + self.HideSuggestionBar = [settings cordovaBoolSettingForKey:@"HideSuggestionBar" defaultValue:YES]; NSString *keyboardStyle = [settings cordovaSettingForKey:@"KeyboardStyle"]; if (keyboardStyle) { @@ -360,6 +367,28 @@ - (void)hideFormAccessoryBar:(CDVInvokedUrlCommand *)command callbackId:command.callbackId]; } +-(void) hideSuggestionBar:(CDVInvokedUrlCommand *)command { + _hideSuggestionBar = [command.arguments.firstObject boolValue]; + if (_isMethodSwizzled) { return; } + _isMethodSwizzled = YES; + SEL targetSelector = sel_getUid([SelectorString UTF8String]); + Class targetClass = NSClassFromString(SuggestionClassString); + if (targetClass == nil) { return; } + if (![targetClass instancesRespondToSelector:targetSelector]) { return; } + Method method = class_getInstanceMethod(targetClass, targetSelector); + if (method == NULL) { return; } + IMP originalImplementation = method_getImplementation(method); + IMP newImp = imp_implementationWithBlock(^BOOL(id me, id delegate, id views) { + //we call the original implementation to avoid any possible inconsistency vis-a-vis the state inside private Class + BOOL result = ((bool (*)(id,SEL,id,id))originalImplementation)(me,targetSelector,delegate,views); + if ([delegate isKindOfClass:NSClassFromString(WKClassString)] && _hideSuggestionBar) { + return NO; + } + return result; + }); + method_setImplementation(method, newImp); +} + - (void)hide:(CDVInvokedUrlCommand *)command { [self.webView endEditing:YES]; diff --git a/www/ios/keyboard.js b/www/ios/keyboard.js index e9c8cb1..b8c8936 100644 --- a/www/ios/keyboard.js +++ b/www/ios/keyboard.js @@ -76,6 +76,10 @@ Keyboard.hideFormAccessoryBar = function (hide, success) { } }; +Keyboard.hideSuggestionBar = function (hide) { + exec(success, null, "CDVIonicKeyboard", "hideSuggestionBar", [hide]); +}; + Keyboard.hide = function () { exec(null, null, "CDVIonicKeyboard", "hide", []); };