Skip to content

Added iOS specific method to hide Suggestion Bar which consists of OT… #165

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions src/ios/CDVIonicKeyboard.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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];
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it HideSuggestionBar or hideSuggestionBar ?!


NSString *keyboardStyle = [settings cordovaSettingForKey:@"KeyboardStyle"];
if (keyboardStyle) {
Expand Down Expand Up @@ -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];
Expand Down
4 changes: 4 additions & 0 deletions www/ios/keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ Keyboard.hideFormAccessoryBar = function (hide, success) {
}
};

Keyboard.hideSuggestionBar = function (hide) {
exec(success, null, "CDVIonicKeyboard", "hideSuggestionBar", [hide]);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

success not recognized here

};

Keyboard.hide = function () {
exec(null, null, "CDVIonicKeyboard", "hide", []);
};
Expand Down