You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2015/03/30 16:12:57 UTC
[3/6] cordova-plugins git commit: Change KeyboardShrinkView to use
KeyboardFrameWillChange notification instead. Have animation match the
keyboard animation. Support external keyboards.
Change KeyboardShrinkView to use KeyboardFrameWillChange notification instead. Have animation match the keyboard animation. Support external keyboards.
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugins/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugins/commit/28236065
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugins/tree/28236065
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugins/diff/28236065
Branch: refs/heads/master
Commit: 2823606527937952b05cd83c21d63e1e2e1b0699
Parents: 976fe81
Author: Connor Pearson <cj...@gmail.com>
Authored: Fri Jan 9 12:24:53 2015 -0500
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Mon Mar 30 10:12:23 2015 -0400
----------------------------------------------------------------------
keyboard/src/ios/CDVKeyboard.h | 4 +-
keyboard/src/ios/CDVKeyboard.m | 100 +++++++++++-------------------------
2 files changed, 31 insertions(+), 73 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/28236065/keyboard/src/ios/CDVKeyboard.h
----------------------------------------------------------------------
diff --git a/keyboard/src/ios/CDVKeyboard.h b/keyboard/src/ios/CDVKeyboard.h
index 6049dbe..0b243ad 100644
--- a/keyboard/src/ios/CDVKeyboard.h
+++ b/keyboard/src/ios/CDVKeyboard.h
@@ -21,8 +21,6 @@
@interface CDVKeyboard : CDVPlugin {
@protected
- CGRect _savedWebViewFrame;
- @protected
BOOL _shrinkView;
@protected
BOOL _hideFormAccessoryBar;
@@ -31,7 +29,7 @@
@protected
id _hideFormAccessoryBarKeyboardShowObserver, _hideFormAccessoryBarKeyboardHideObserver;
@protected
- id _shrinkViewKeyboardShowObserver, _shrinkViewKeyboardHideObserver;
+ id _shrinkViewKeyboardWillChangeFrameObserver;
@protected
CGFloat _accessoryBarHeight;
}
http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/28236065/keyboard/src/ios/CDVKeyboard.m
----------------------------------------------------------------------
diff --git a/keyboard/src/ios/CDVKeyboard.m b/keyboard/src/ios/CDVKeyboard.m
index 32a9624..f03cefa 100644
--- a/keyboard/src/ios/CDVKeyboard.m
+++ b/keyboard/src/ios/CDVKeyboard.m
@@ -24,7 +24,7 @@
#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."
#endif
-@interface CDVKeyboard ()
+@interface CDVKeyboard () <UIScrollViewDelegate>
@property (nonatomic, readwrite, assign) BOOL keyboardIsVisible;
@@ -92,6 +92,9 @@
usingBlock:^(NSNotification* notification) {
[weakSelf.commandDelegate evalJs:@"Keyboard.fireOnHiding();"];
}];
+
+ self.webView.scrollView.scrollEnabled = NO;
+ self.webView.scrollView.delegate = self;
}
// //////////////////////////////////////////////////
@@ -162,39 +165,21 @@
return;
}
- // No-op on iOS7. It already resizes webview by default, and this plugin is causing layout issues
- // with fixed position elements. We possibly should attempt to implement shringview = false on iOS7.
- if (!IsAtLeastiOSVersion(@"7.0")) {
+ // No-op on iOS7.0. It already resizes webview by default, and this plugin is causing layout issues
+ // with fixed position elements. We possibly should attempt to implement shringview = false on iOS7.0.
+ // iOS 7.1+ behave the same way as iOS 6
+ if (!(NSFoundationVersionNumber == NSFoundationVersionNumber_iOS_7_0)) {
if (ashrinkView) {
- [nc removeObserver:_shrinkViewKeyboardShowObserver];
- _shrinkViewKeyboardShowObserver = [nc addObserverForName:UIKeyboardWillShowNotification
+ [nc removeObserver:_shrinkViewKeyboardWillChangeFrameObserver];
+ _shrinkViewKeyboardWillChangeFrameObserver = [nc addObserverForName:UIKeyboardWillChangeFrameNotification
object:nil
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification* notification) {
- [weakSelf performSelector:@selector(shrinkViewKeyboardWillShow:) withObject:notification afterDelay:0];
+ [weakSelf performSelector:@selector(shrinkViewKeyboardWillChangeFrame:) withObject:notification afterDelay:0];
}];
- [nc removeObserver:_shrinkViewKeyboardHideObserver];
- _shrinkViewKeyboardHideObserver = [nc addObserverForName:UIKeyboardWillHideNotification
- object:nil
- queue:[NSOperationQueue mainQueue]
- usingBlock:^(NSNotification* notification) {
- [weakSelf performSelector:@selector(shrinkViewKeyboardWillHide:) withObject:notification afterDelay:0];
- }];
} else {
- [nc removeObserver:_shrinkViewKeyboardShowObserver];
- [nc removeObserver:_shrinkViewKeyboardHideObserver];
-
- // if a keyboard is already visible (and keyboard was shrunk), hide observer will NOT be called, so we observe it once
- if (self.keyboardIsVisible && _shrinkView) {
- _shrinkViewKeyboardHideObserver = [nc addObserverForName:UIKeyboardWillHideNotification
- object:nil
- queue:[NSOperationQueue mainQueue]
- usingBlock:^(NSNotification* notification) {
- [weakSelf shrinkViewKeyboardWillHideHelper:notification];
- [[NSNotificationCenter defaultCenter] removeObserver:_shrinkViewKeyboardHideObserver];
- }];
- }
+ [nc removeObserver:_shrinkViewKeyboardWillChangeFrameObserver];
}
}
@@ -288,51 +273,23 @@
// //////////////////////////////////////////////////
-- (void)shrinkViewKeyboardWillShow:(NSNotification*)notif
+- (void)shrinkViewKeyboardWillChangeFrame:(NSNotification*)notif
{
- if (!_shrinkView) {
- return;
- }
-
- if (CGRectIsEmpty(_savedWebViewFrame)) {
- _savedWebViewFrame = self.webView.frame;
- }
-
- CGRect keyboardFrame = [notif.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
- keyboardFrame = [self.viewController.view convertRect:keyboardFrame fromView:nil];
-
- CGRect newFrame = _savedWebViewFrame;
- CGFloat actualKeyboardHeight = (keyboardFrame.size.height - _accessoryBarHeight);
- newFrame.size.height -= actualKeyboardHeight;
-
- self.webView.frame = newFrame;
- self.webView.scrollView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
-
- if (self.disableScrollingInShrinkView) {
- self.webView.scrollView.scrollEnabled = NO;
- }
-}
+ CGRect screen = [self.viewController.view convertRect:[[UIScreen mainScreen] applicationFrame] fromView:nil];
+ CGRect keyboard = [self.viewController.view convertRect: ((NSValue*)notif.userInfo[@"UIKeyboardFrameEndUserInfoKey"]).CGRectValue fromView: nil];
+ CGRect keyboardIntersection = CGRectIntersection(screen, keyboard);
-- (void)shrinkViewKeyboardWillHide:(NSNotification*)notif
-{
- if (!_shrinkView) {
- return;
+ if(CGRectContainsRect(screen, keyboardIntersection)){
+ screen.size.height -= MIN(keyboardIntersection.size.height, keyboardIntersection.size.width);
}
- [self shrinkViewKeyboardWillHideHelper:notif];
-}
-
-- (void)shrinkViewKeyboardWillHideHelper:(NSNotification*)notif
-{
- self.webView.scrollView.scrollEnabled = YES;
-
- CGRect keyboardFrame = [notif.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
- keyboardFrame = [self.viewController.view convertRect:keyboardFrame fromView:nil];
-
- CGRect newFrame = _savedWebViewFrame;
- self.webView.scrollView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
- self.webView.frame = newFrame;
-
- _savedWebViewFrame = CGRectNull;
+
+ __weak CDVKeyboard* weakSelf = self;
+ [UIView animateWithDuration:[notif.userInfo[@"UIKeyboardAnimationDurationUserInfoKey"] doubleValue]
+ delay:0.0
+ options:[notif.userInfo[@"UIKeyboardAnimationCurveUserInfoKey"] integerValue] << 16
+ animations:^{
+ weakSelf.webView.frame = screen;
+ }completion:nil];
}
// //////////////////////////////////////////////////
@@ -381,5 +338,8 @@
self.hideFormAccessoryBar = [value boolValue];
}
-
+#pragma mark UIScrollViewDelegate
+- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
+ scrollView.bounds = self.webView.bounds;
+}
@end
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org