-
Notifications
You must be signed in to change notification settings - Fork 6k
[iOS] [iPad] fix avoid bottom inset in split view mode #35535
Changes from all commits
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 |
---|---|---|
|
@@ -297,11 +297,6 @@ - (void)setupNotificationCenterObservers { | |
name:UIKeyboardWillChangeFrameNotification | ||
object:nil]; | ||
|
||
[center addObserver:self | ||
selector:@selector(keyboardWillBeHidden:) | ||
name:UIKeyboardWillHideNotification | ||
object:nil]; | ||
|
||
[center addObserver:self | ||
selector:@selector(onAccessibilityStatusChanged:) | ||
name:UIAccessibilityVoiceOverStatusChanged | ||
|
@@ -1190,12 +1185,19 @@ - (void)updateViewportPadding { | |
|
||
#pragma mark - Keyboard events | ||
|
||
// using keyboardWillChangeFrame instead of keyboardWill(Show/Hide) because of split/floating | ||
// keyboard on iPad | ||
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. Capital letter at the beginning and period at the end. Also maybe link to the issue. 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. I'll fix that this week 👍 |
||
- (void)keyboardWillChangeFrame:(NSNotification*)notification { | ||
CGRect screenRect = [[UIScreen mainScreen] bounds]; | ||
NSDictionary* info = [notification userInfo]; | ||
CGRect keyboardFrame = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; | ||
|
||
// Ignore keyboard notifications related to other apps. | ||
// Ignore keyboard notifications related to other apps if not dismissing. | ||
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. What happens if you show the keyboard in the other app, then tap the Flutter app's text field? I haven't tried it, just curious. 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. It works normally,
I can make a video if necessary |
||
bool isDismissing = | ||
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. Maybe: bool isShowing = CGRectIntersection(keyboardFrame, screenRect); 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. Good point, I'll fix that this week 👍 |
||
CGRectEqualToRect(keyboardFrame, CGRectZero) || | ||
keyboardFrame.origin.y >= screenRect.size.height; // CGRectZero for floating keyboard on iPad | ||
id isLocal = info[UIKeyboardIsLocalUserInfoKey]; | ||
if (isLocal && ![isLocal boolValue]) { | ||
if (!isDismissing && isLocal && ![isLocal boolValue]) { | ||
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. Have you tested If the keyboard is brought be by the other app, does the Flutter app's bottom inset adjust? This logic here seems to prevent Flutter app's bottom inset to be adjusted to the correct value in that case. Which is what I was saying in: flutter/flutter#109845 (comment) 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. As I wrote to @justinmc, if the keyboard is brought by an other app:
This is the correct behavior since natives apps have that one. |
||
return; | ||
} | ||
|
||
|
@@ -1204,13 +1206,6 @@ - (void)keyboardWillChangeFrame:(NSNotification*)notification { | |
return; | ||
} | ||
|
||
CGRect keyboardFrame = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; | ||
CGRect screenRect = [[UIScreen mainScreen] bounds]; | ||
|
||
// Get the animation duration | ||
NSTimeInterval duration = | ||
[[info objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]; | ||
|
||
// 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)) { | ||
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 line can be changed to 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. I'll fix that this week 👍 |
||
|
@@ -1223,32 +1218,11 @@ - (void)keyboardWillChangeFrame:(NSNotification*)notification { | |
} else { | ||
self.targetViewInsetBottom = 0; | ||
} | ||
[self startKeyBoardAnimation:duration]; | ||
} | ||
|
||
- (void)keyboardWillBeHidden:(NSNotification*)notification { | ||
NSDictionary* info = [notification userInfo]; | ||
|
||
// Ignore keyboard notifications related to other apps. | ||
id isLocal = info[UIKeyboardIsLocalUserInfoKey]; | ||
if (isLocal && ![isLocal boolValue]) { | ||
return; | ||
} | ||
|
||
// Ignore keyboard notifications if engine’s viewController is not current viewController. | ||
if ([_engine.get() viewController] != self) { | ||
return; | ||
} | ||
|
||
if (self.targetViewInsetBottom != 0) { | ||
// Ensure the keyboard will be dismissed. Just like the keyboardWillChangeFrame, | ||
// keyboardWillBeHidden is also in an animation block in iOS sdk, so we don't need to set the | ||
// animation curve. Related issue: https://github.com/flutter/flutter/issues/99951 | ||
self.targetViewInsetBottom = 0; | ||
NSTimeInterval duration = | ||
[[info objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]; | ||
[self startKeyBoardAnimation:duration]; | ||
} | ||
// Get the animation duration | ||
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. Nit: Period at the end (I know you didn't write this comment, but it's a good chance to fix it! 😁). 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. I'll fix that this week 👍 |
||
NSTimeInterval duration = | ||
[[info objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]; | ||
[self startKeyBoardAnimation:duration]; | ||
} | ||
|
||
- (void)startKeyBoardAnimation:(NSTimeInterval)duration { | ||
|
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.
The comment says "keybaordWill(show/hide), but we don't have a "keyboardWillShow", maybe just "keyboardWillBeHidden"?
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.
keyboardWillShow/keyboardWillHide are part of the UIKit framework; so keyboardWillBeHidden is not appropriated here and my comment is still relevant 🙂
BTW I tried to answer to you in my opened issue last week but I could not without closing the issue.
(nothing related but I loved the document you wrote related to blurs... so interesting to read !)