-
Notifications
You must be signed in to change notification settings - Fork 344
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
Fix ios 12 black area when keyboard is showing and shrink param is true #85
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ Licensed to the Apache Software Foundation (ASF) under one | |
@interface CDVKeyboard () <UIScrollViewDelegate> | ||
|
||
@property (nonatomic, readwrite, assign) BOOL keyboardIsVisible; | ||
@property (readwrite, assign) CGFloat keyboardHeight; | ||
|
||
@end | ||
|
||
|
@@ -193,10 +194,14 @@ - (void)shrinkViewKeyboardWillChangeFrame:(NSNotification*)notif | |
// Note: we check for _shrinkView at this point instead of the beginning of the method to handle | ||
// the case where the user disabled shrinkView while the keyboard is showing. | ||
// The webview should always be able to return to full size | ||
_shrinkView = YES; | ||
CGRect keyboardIntersection = CGRectIntersection(screen, keyboard); | ||
if (CGRectContainsRect(screen, keyboardIntersection) && !CGRectIsEmpty(keyboardIntersection) && _shrinkView && self.keyboardIsVisible) { | ||
screen.size.height -= keyboardIntersection.size.height; | ||
self.webView.scrollView.scrollEnabled = !self.disableScrollingInShrinkView; | ||
self.keyboardHeight = keyboardIntersection.size.height; | ||
|
||
// self.webView.scrollView.scrollEnabled = !self.disableScrollingInShrinkView; | ||
self.webView.scrollView.scrollEnabled = NO; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should not force this to |
||
} | ||
|
||
// A view's frame is in its superview's coordinate system so we need to convert again | ||
|
@@ -207,12 +212,24 @@ - (void)shrinkViewKeyboardWillChangeFrame:(NSNotification*)notif | |
|
||
- (void)scrollViewDidScroll:(UIScrollView*)scrollView | ||
{ | ||
/* | ||
Costin Moraru | ||
|
||
On ios 12 with default cordova webview won't scroll webview content to bottom with bounds. | ||
Used setContentOffset to scroll webview content to 0.0f. | ||
|
||
*/ | ||
// if (_shrinkView && _keyboardIsVisible) { | ||
// CGFloat maxY = scrollView.contentSize.height - scrollView.bounds.size.height; | ||
// if (scrollView.bounds.origin.y > maxY) { | ||
// scrollView.bounds = CGRectMake(scrollView.bounds.origin.x, maxY, | ||
// scrollView.bounds.size.width, scrollView.bounds.size.height); | ||
// } | ||
// } | ||
if (_shrinkView && _keyboardIsVisible) { | ||
CGFloat maxY = scrollView.contentSize.height - scrollView.bounds.size.height; | ||
if (scrollView.bounds.origin.y > maxY) { | ||
scrollView.bounds = CGRectMake(scrollView.bounds.origin.x, maxY, | ||
scrollView.bounds.size.width, scrollView.bounds.size.height); | ||
} | ||
// Scroll webview content to bottom | ||
CGPoint bottomOffset = CGPointMake(0.0f, 0.0f); | ||
[self.webView.scrollView setContentOffset:bottomOffset animated:NO]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This works, but doesn't match expectations across the board. This scrollsToTop when the keyboard is opened. In some instances that means scrolling the input out of view. |
||
} | ||
} | ||
|
||
|
@@ -227,6 +244,9 @@ - (void)shrinkView:(CDVInvokedUrlCommand*)command | |
} | ||
|
||
self.shrinkView = [value boolValue]; | ||
// Scroll webview content to bottom | ||
CGPoint bottomOffset = CGPointMake(0.0f, 0.0f); | ||
[self.webView.scrollView setContentOffset:bottomOffset animated:NO]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function |
||
} | ||
|
||
[self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:self.shrinkView] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should not force this to
YES
. This overrides settings users have made.