Skip to content
This repository was archived by the owner on Apr 2, 2018. It is now read-only.
Merged
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
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The `cordova.plugins.Keyboard` object provides functions to make interacting wit
Methods
-------

- ~~cordova.plugins.Keyboard.hideKeyboardAccessoryBar~~ (**removed in 2.0, see below**)
- cordova.plugins.Keyboard.hideKeyboardAccessoryBar
- cordova.plugins.Keyboard.close
- cordova.plugins.Keyboard.disableScroll
- cordova.plugins.Keyboard.show
Expand All @@ -30,11 +30,9 @@ These events are fired on the window.

# API reference

~~Keyboard.hideKeyboardAccessoryBar~~
Keyboard.hideKeyboardAccessoryBar
=================

**NOTE: This method started causing apps to be rejected from the App Store, so has been removed until a workaround is found.**

Hide the keyboard accessory bar with the next, previous and done buttons.

cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
Expand Down
5 changes: 0 additions & 5 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,8 @@
<param name="ios-package" value="IonicKeyboard" onload="true" />
</feature>
</config-file>

<header-file src="src/ios/IonicKeyboard.h" />
<source-file src="src/ios/IonicKeyboard.m" />
<!--
<header-file src="src/ios/UIWebViewExtension.h" />
<source-file src="src/ios/UIWebViewExtension.m" />
-->
</platform>

<!-- browser -->
Expand Down
5 changes: 4 additions & 1 deletion src/ios/IonicKeyboard.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#import <Cordova/CDVPlugin.h>
#import <objc/runtime.h>

@interface IonicKeyboard : CDVPlugin <UIScrollViewDelegate> {
@protected
id _keyboardShowObserver, _keyboardHideObserver;
IMP wkOriginalImp, uiOriginalImp, nilImp;
Method wkMethod, uiMethod;
}

// @property (readwrite, assign) BOOL hideKeyboardAccessoryBar;
@property (readwrite, assign) BOOL hideKeyboardAccessoryBar;
@property (readwrite, assign) BOOL disableScroll;
//@property (readwrite, assign) BOOL styleDark;

Expand Down
78 changes: 46 additions & 32 deletions src/ios/IonicKeyboard.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,29 @@

@implementation IonicKeyboard

// @synthesize hideKeyboardAccessoryBar = _hideKeyboardAccessoryBar;
@synthesize hideKeyboardAccessoryBar = _hideKeyboardAccessoryBar;
@synthesize disableScroll = _disableScroll;
//@synthesize styleDark = _styleDark;

- (void)pluginInitialize {

NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
__weak IonicKeyboard* weakSelf = self;

Class wkClass = NSClassFromString([@[@"UI", @"Web", @"Browser", @"View"] componentsJoinedByString:@""]);
wkMethod = class_getInstanceMethod(wkClass, @selector(inputAccessoryView));
wkOriginalImp = method_getImplementation(wkMethod);
Class uiClass = NSClassFromString([@[@"WK", @"Content", @"View"] componentsJoinedByString:@""]);
uiMethod = class_getInstanceMethod(uiClass, @selector(inputAccessoryView));
uiOriginalImp = method_getImplementation(uiMethod);
nilImp = imp_implementationWithBlock(^(id _s) {
return nil;
});

//set defaults
// self.hideKeyboardAccessoryBar = YES;
self.hideKeyboardAccessoryBar = YES;
self.disableScroll = NO;
//self.styleDark = NO;


NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
__weak IonicKeyboard* weakSelf = self;
_keyboardShowObserver = [nc addObserverForName:UIKeyboardWillShowNotification
object:nil
queue:[NSOperationQueue mainQueue]
Expand All @@ -42,6 +51,7 @@ - (void)pluginInitialize {
[weakSelf.commandDelegate evalJs:@"cordova.fireWindowEvent('native.hidekeyboard'); "];
}];
}

- (BOOL)disableScroll {
return _disableScroll;
}
Expand All @@ -62,24 +72,28 @@ - (void)setDisableScroll:(BOOL)disableScroll {
_disableScroll = disableScroll;
}

//keyboard swizzling inspired by:
//https://github.com/cjpearson/cordova-plugin-keyboard/

- (BOOL)hideKeyboardAccessoryBar {
return _hideKeyboardAccessoryBar;
}

// - (BOOL)hideKeyboardAccessoryBar {
// return _hideKeyboardAccessoryBar;
// }
//
// - (void)setHideKeyboardAccessoryBar:(BOOL)hideKeyboardAccessoryBar {
// if (hideKeyboardAccessoryBar == _hideKeyboardAccessoryBar || ![self.webView isKindOfClass:[UIWebView class]]) {
// return;
// }
// if (hideKeyboardAccessoryBar) {
// ((UIWebView*)self.webView).hackishlyHidesInputAccessoryView = YES;
// }
// else {
// ((UIWebView*)self.webView).hackishlyHidesInputAccessoryView = NO;
// }
//
// _hideKeyboardAccessoryBar = hideKeyboardAccessoryBar;
// }
- (void)setHideKeyboardAccessoryBar:(BOOL)hideKeyboardAccessoryBar {
if (hideKeyboardAccessoryBar == _hideKeyboardAccessoryBar) {
return;
}

if (hideKeyboardAccessoryBar) {
method_setImplementation(wkMethod, nilImp);
method_setImplementation(uiMethod, nilImp);
} else {
method_setImplementation(wkMethod, wkOriginalImp);
method_setImplementation(uiMethod, uiOriginalImp);
}

_hideKeyboardAccessoryBar = hideKeyboardAccessoryBar;
}

/*
- (BOOL)styleDark {
Expand Down Expand Up @@ -129,15 +143,15 @@ - (void) disableScroll:(CDVInvokedUrlCommand*)command {
}
}

// - (void) hideKeyboardAccessoryBar:(CDVInvokedUrlCommand*)command {
// if (!command.arguments || ![command.arguments count]){
// return;
// }
// id value = [command.arguments objectAtIndex:0];
// if (value != [NSNull null]) {
// self.hideKeyboardAccessoryBar = [value boolValue];
// }
// }
- (void) hideKeyboardAccessoryBar:(CDVInvokedUrlCommand*)command {
if (!command.arguments || ![command.arguments count]){
return;
}
id value = [command.arguments objectAtIndex:0];
if (value != [NSNull null]) {
self.hideKeyboardAccessoryBar = [value boolValue];
}
}

- (void) close:(CDVInvokedUrlCommand*)command {
[self.webView endEditing:YES];
Expand Down
4 changes: 0 additions & 4 deletions src/ios/UIWebViewExtension.h

This file was deleted.

109 changes: 0 additions & 109 deletions src/ios/UIWebViewExtension.m

This file was deleted.

3 changes: 1 addition & 2 deletions www/ios/keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ var Keyboard = function() {
};

Keyboard.hideKeyboardAccessoryBar = function(hide) {
// exec(null, null, "Keyboard", "hideKeyboardAccessoryBar", [hide]);
console.warn('hideKeyboardAccessoryBar has been temporarily removed on iOS until an Apple-approved method is found.');
exec(null, null, "Keyboard", "hideKeyboardAccessoryBar", [hide]);
};

Keyboard.close = function() {
Expand Down