123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- #import "IonicKeyboard.h"
- // #import "UIWebViewExtension.h"
- #import <Cordova/CDVAvailability.h>
- @implementation IonicKeyboard
- // @synthesize hideKeyboardAccessoryBar = _hideKeyboardAccessoryBar;
- @synthesize disableScroll = _disableScroll;
- //@synthesize styleDark = _styleDark;
- - (void)pluginInitialize {
- NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
- __weak IonicKeyboard* weakSelf = self;
- //set defaults
- // self.hideKeyboardAccessoryBar = YES;
- self.disableScroll = NO;
- //self.styleDark = NO;
- _keyboardShowObserver = [nc addObserverForName:UIKeyboardWillShowNotification
- object:nil
- queue:[NSOperationQueue mainQueue]
- usingBlock:^(NSNotification* notification) {
- CGRect keyboardFrame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
- keyboardFrame = [self.viewController.view convertRect:keyboardFrame fromView:nil];
- [weakSelf.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.plugins.Keyboard.isVisible = true; cordova.fireWindowEvent('native.keyboardshow', { 'keyboardHeight': %@ }); ", [@(keyboardFrame.size.height) stringValue]]];
- //deprecated
- [weakSelf.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireWindowEvent('native.showkeyboard', { 'keyboardHeight': %@ }); ", [@(keyboardFrame.size.height) stringValue]]];
- }];
- _keyboardHideObserver = [nc addObserverForName:UIKeyboardWillHideNotification
- object:nil
- queue:[NSOperationQueue mainQueue]
- usingBlock:^(NSNotification* notification) {
- [weakSelf.commandDelegate evalJs:@"cordova.plugins.Keyboard.isVisible = false; cordova.fireWindowEvent('native.keyboardhide'); "];
- //deprecated
- [weakSelf.commandDelegate evalJs:@"cordova.fireWindowEvent('native.hidekeyboard'); "];
- }];
- }
- - (BOOL)disableScroll {
- return _disableScroll;
- }
- - (void)setDisableScroll:(BOOL)disableScroll {
- if (disableScroll == _disableScroll) {
- return;
- }
- if (disableScroll) {
- self.webView.scrollView.scrollEnabled = NO;
- self.webView.scrollView.delegate = self;
- }
- else {
- self.webView.scrollView.scrollEnabled = YES;
- self.webView.scrollView.delegate = nil;
- }
- _disableScroll = disableScroll;
- }
- // - (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;
- // }
- /*
- - (BOOL)styleDark {
- return _styleDark;
- }
- - (void)setStyleDark:(BOOL)styleDark {
- if (styleDark == _styleDark) {
- return;
- }
- if (styleDark) {
- self.webView.styleDark = YES;
- }
- else {
- self.webView.styleDark = NO;
- }
- _styleDark = styleDark;
- }
- */
- /* ------------------------------------------------------------- */
- - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
- [scrollView setContentOffset: CGPointZero];
- }
- /* ------------------------------------------------------------- */
- - (void)dealloc {
- NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
- [nc removeObserver:self name:UIKeyboardWillShowNotification object:nil];
- [nc removeObserver:self name:UIKeyboardWillHideNotification object:nil];
- }
- /* ------------------------------------------------------------- */
- - (void) disableScroll:(CDVInvokedUrlCommand*)command {
- if (!command.arguments || ![command.arguments count]){
- return;
- }
- id value = [command.arguments objectAtIndex:0];
- if (value != [NSNull null]) {
- self.disableScroll = [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];
- }
- - (void) show:(CDVInvokedUrlCommand*)command {
- NSLog(@"Showing keyboard not supported in iOS due to platform limitations.");
- }
- /*
- - (void) styleDark:(CDVInvokedUrlCommand*)command {
- if (!command.arguments || ![command.arguments count]){
- return;
- }
- id value = [command.arguments objectAtIndex:0];
- self.styleDark = [value boolValue];
- }
- */
- @end
|