diff --git a/README.md b/README.md index e930405..c084261 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ Shrink the WebView when the keyboard comes up. Set to true to shrink the WebView when the keyboard comes up. The WebView shrinks instead of the viewport shrinking and the page scrollable. This applies to apps that position their elements relative to the bottom of the WebView. This is the default behaviour on Android, and makes a lot of sense when building apps as opposed to webpages. +**Fixed scroll the content to bottom when keyboard is showing and the shrinkview param is true. Work with meta viewport-fit=cover fix for iphone x.** #### Supported Platforms diff --git a/src/ios/CDVKeyboard.m b/src/ios/CDVKeyboard.m index 3c04548..e470c88 100644 --- a/src/ios/CDVKeyboard.m +++ b/src/ios/CDVKeyboard.m @@ -28,6 +28,7 @@ Licensed to the Apache Software Foundation (ASF) under one @interface CDVKeyboard () @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; } // 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]; } } @@ -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]; } [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:self.shrinkView]