From 9fc1f2f42c75764ecb2bd30399d5da8133d2a82f Mon Sep 17 00:00:00 2001 From: Connor Pearson Date: Thu, 23 Jul 2015 20:47:56 -0400 Subject: [PATCH] Refactor how hiding the accessory bar works. Relates to #3 --- src/ios/CDVKeyboard.h | 8 +-- src/ios/CDVKeyboard.m | 137 +++++------------------------------------- 2 files changed, 17 insertions(+), 128 deletions(-) diff --git a/src/ios/CDVKeyboard.h b/src/ios/CDVKeyboard.h index d69ef78..4c3f90d 100644 --- a/src/ios/CDVKeyboard.h +++ b/src/ios/CDVKeyboard.h @@ -27,17 +27,13 @@ @protected id _keyboardShowObserver, _keyboardHideObserver, _keyboardWillShowObserver, _keyboardWillHideObserver; @protected - id _hideFormAccessoryBarKeyboardShowObserver, _hideFormAccessoryBarKeyboardHideObserver; - @protected id _shrinkViewKeyboardWillChangeFrameObserver; - @protected - CGFloat _accessoryBarHeight; } @property (readwrite, assign) BOOL shrinkView; @property (readwrite, assign) BOOL disableScrollingInShrinkView; -@property (readwrite, assign) BOOL hideFormAccessoryBar; -@property (readonly, assign) BOOL keyboardIsVisible; +@property (readwrite, assign) BOOL hideFormAccessoryBar; +@property (readonly, assign) BOOL keyboardIsVisible; - (void) shrinkView:(CDVInvokedUrlCommand*)command; - (void) disableScrollingInShrinkView:(CDVInvokedUrlCommand*)command; diff --git a/src/ios/CDVKeyboard.m b/src/ios/CDVKeyboard.m index 8100b48..c696e19 100644 --- a/src/ios/CDVKeyboard.m +++ b/src/ios/CDVKeyboard.m @@ -19,6 +19,7 @@ Licensed to the Apache Software Foundation (ASF) under one #import "CDVKeyboard.h" #import +#import #ifndef __CORDOVA_3_2_0 #warning "The keyboard plugin is only supported in Cordova 3.2 or greater, it may not work properly in an older version. If you do use this plugin in an older version, make sure the HideKeyboardFormAccessoryBar and KeyboardShrinksView preference values are false." @@ -102,8 +103,6 @@ - (void)pluginInitialize }]; self.webView.scrollView.delegate = self; - - _accessoryBarHeight = 44; } #pragma mark HideFormAccessoryBar @@ -113,131 +112,31 @@ - (BOOL)hideFormAccessoryBar return _hideFormAccessoryBar; } +static IMP originalImp; + - (void)setHideFormAccessoryBar:(BOOL)ahideFormAccessoryBar { - NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; - __weak CDVKeyboard* weakSelf = self; - if (ahideFormAccessoryBar == _hideFormAccessoryBar) { return; } - if (ahideFormAccessoryBar) { - [nc removeObserver:_hideFormAccessoryBarKeyboardShowObserver]; - _hideFormAccessoryBarKeyboardShowObserver = [nc addObserverForName:UIKeyboardWillShowNotification - object:nil - queue:[NSOperationQueue mainQueue] - usingBlock:^(NSNotification* notification) { - // we can't hide it here because the accessory bar hasn't been created yet, so we delay on the queue - [weakSelf performSelector:@selector(formAccessoryBarKeyboardWillShow:) withObject:notification afterDelay:0]; - }]; - - [nc removeObserver:_hideFormAccessoryBarKeyboardHideObserver]; - _hideFormAccessoryBarKeyboardHideObserver = [nc addObserverForName:UIKeyboardWillHideNotification - object:nil - queue:[NSOperationQueue mainQueue] - usingBlock:^(NSNotification* notification) { - [weakSelf formAccessoryBarKeyboardWillHide:notification]; - }]; - } else { - [nc removeObserver:_hideFormAccessoryBarKeyboardShowObserver]; - [nc removeObserver:_hideFormAccessoryBarKeyboardHideObserver]; - - // if a keyboard is already visible (and the accessorybar was hidden), hide observer will NOT be called, so we observe it once - if (self.keyboardIsVisible && _hideFormAccessoryBar) { - _hideFormAccessoryBarKeyboardHideObserver = [nc addObserverForName:UIKeyboardWillHideNotification - object:nil - queue:[NSOperationQueue mainQueue] - usingBlock:^(NSNotification* notification) { - [weakSelf formAccessoryBarKeyboardWillHide:notification]; - [[NSNotificationCenter defaultCenter] removeObserver:_hideFormAccessoryBarKeyboardHideObserver]; - }]; - } - } - - _hideFormAccessoryBar = ahideFormAccessoryBar; -} - -- (NSArray*)getKeyboardViews:(UIView*)viewToSearch{ - NSArray *subViews; - - for (UIView *possibleFormView in viewToSearch.subviews) { - if ([[possibleFormView description] hasPrefix: self.getKeyboardFirstLevelIdentifier]) { - if(IsAtLeastiOSVersion(@"8.0")){ - for (UIView* subView in possibleFormView.subviews) { - return subView.subviews; - } - }else{ - return possibleFormView.subviews; - } - } - - } - return subViews; -} - -- (NSString*)getKeyboardFirstLevelIdentifier{ - if(!IsAtLeastiOSVersion(@"8.0")){ - return @"