From fee9895d513780da885dbfd89464e4de88449886 Mon Sep 17 00:00:00 2001 From: Ryoichi Izumita Date: Wed, 8 Apr 2020 03:27:15 +0900 Subject: [PATCH] Fixed a bug that left a blank at the bottom of the screen (flutter/engine#17474) I fixed a bug that left a blank at the bottom of the screen when the iPad's split keyboard was hidden. I also had the same problem with this issue, so I fixed it. iPad split keyboard cause a blank space problem There is no function to change the space size at the bottom of the screen when the split keyboard is moved. This is because it's not clear what the keyboard should do when it's moved to the top of the screen. --- .../framework/Source/FlutterViewController.mm | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm index e6906d8d075..2c5f4ebb6d3 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm @@ -953,13 +953,23 @@ static flutter::PointerData::DeviceKind DeviceKindFromTouchType(UITouch* touch) - (void)keyboardWillChangeFrame:(NSNotification*)notification { NSDictionary* info = [notification userInfo]; - CGFloat bottom = CGRectGetHeight([[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]); - CGFloat scale = [UIScreen mainScreen].scale; + CGRect keyboardFrame = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; + CGRect screenRect = [[UIScreen mainScreen] bounds]; + + // Considering the iPad's split keyboard, Flutter needs to check if the keyboard frame is present + // in the screen to see if the keyboard is visible. + if (CGRectIntersectsRect(keyboardFrame, screenRect)) { + CGFloat bottom = CGRectGetHeight(keyboardFrame); + CGFloat scale = [UIScreen mainScreen].scale; + + // The keyboard is treated as an inset since we want to effectively reduce the window size by + // the keyboard height. The Dart side will compute a value accounting for the keyboard-consuming + // bottom padding. + _viewportMetrics.physical_view_inset_bottom = bottom * scale; + } else { + _viewportMetrics.physical_view_inset_bottom = 0; + } - // The keyboard is treated as an inset since we want to effectively reduce the window size by the - // keyboard height. The Dart side will compute a value accounting for the keyboard-consuming - // bottom padding. - _viewportMetrics.physical_view_inset_bottom = bottom * scale; [self updateViewportMetrics]; }