Skip to content
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

Account for blue status bar height when shrinking keyboard #54

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
9 changes: 7 additions & 2 deletions src/ios/CDVKeyboard.m
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ - (void)setShrinkView:(BOOL)shrinkView
// They removed this behavior is iOS 10, but for 8 and 9 we need to prevent the webview from listening on keyboard events
// Even if you later set shrinkView to false, the observers will not be added back
NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
if ([self.webView isKindOfClass:NSClassFromString(@"WKWebView")]
&& ![[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){.majorVersion = 10, .minorVersion = 0, .patchVersion = 0 }]) {
if ([self.webView isKindOfClass:NSClassFromString(@"WKWebView")]) {
[nc removeObserver:self.webView name:UIKeyboardWillHideNotification object:nil];
[nc removeObserver:self.webView name:UIKeyboardWillShowNotification object:nil];
[nc removeObserver:self.webView name:UIKeyboardWillChangeFrameNotification object:nil];
Expand Down Expand Up @@ -200,6 +199,12 @@ - (void)shrinkViewKeyboardWillChangeFrame:(NSNotification*)notif
self.webView.scrollView.scrollEnabled = !self.disableScrollingInShrinkView;
}

// Check if the webview is offset due to the blue navigation status bar.
CGRect webviewFrame = [self.webView convertRect:[self.webView bounds] fromView:self.webView.superview];
float yOffset = webviewFrame.origin.y;
screen.origin.y -= yOffset;
screen.size.height += yOffset;

// A view's frame is in its superview's coordinate system so we need to convert again
self.webView.frame = [self.webView.superview convertRect:screen fromView:self.webView];
}
Expand Down