-
Notifications
You must be signed in to change notification settings - Fork 6k
Preserve safe area #8848
Preserve safe area #8848
Conversation
cbracken
left a comment
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.
Will give a proper review today! Thanks for sending this.
/cc @Hixie for thoughts as well.
shell/platform/darwin/ios/framework/Source/FlutterViewController.mm
Outdated
Show resolved
Hide resolved
|
The build_and_test_host failure is expected, since this will require updates to the framework to account for the new property on Window. |
|
this is getting quite complicated. I think we shouldn't do this unless we accompany it with detailed diagrams explaining all the cases. we also need to update media query and company. |
|
@Hixie - this needs to land before we can update MediaQuery etc. For diagrams, do you think ASCII ones in the docs are good enough, or do we need actual drawings/screenshots for this? I could imagine some screenshots of where these insets are on an iPhone X would be helpful.... |
|
I've added some ASCII diagrams inline in the docs to hopefully clarify this. The basic thrust of this PR is that we shouldn't completely obscure the actual view padding from the framework - most applications just want to know the "padding" as we've been calculating it up until now, but sometimes you really want something positioned center screen regardless of whether they keyboard is visible and consuming that bottom padding or not. |
|
I meant real diagrams in the assets-for-api-docs sense. cc @gspencergoog and @Piinks who would be able to help as they have lots of experience doing those. |
|
One challenge with that is that assets-for-api-docs is Android based, and this change is really more geared towards iPhone X (and later models). I could add some static images to the repo and link to them here though. |
|
We have diagrams of Cupertino widgets in the same way that we have Material widgets: Flutter doesn't actually need to be running on an iPhone to look like one. The thing that is missing is just a path that represents the notch, and a keyboard image to use as a placeholder. |
|
It's the keyboard and bottom soft button that impact this though. I don't think the diagram generator would capture the IME would it? |
|
A diagram doesn't have to literally include the IME. I just mean literally an explanation of what the values all man relative to each other. I would expect it to be schematic. |
lib/ui/window.dart
Outdated
| /// represents the system keyboard, which can cover over the bottom view | ||
| /// padding when visible. | ||
| /// | ||
| /// The [Window.viewInsets] are the physical pixels into which the operation |
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.
typo: operating
cbracken
left a comment
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.
Just a few very minor doc nits.
| if (@available(iOS 11, *)) { | ||
| _viewportMetrics.physical_padding_bottom = self.view.safeAreaInsets.bottom * scale; | ||
| } else { | ||
| _viewportMetrics.physical_padding_top = [self statusBarPadding] * scale; |
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.
Interesting -- this looks like an oversight in the pre-existing code. Oops. Thanks for fixing.
lib/stub_ui/lib/src/ui/window.dart
Outdated
| /// viewPadding and the padding will be equal, as there are no insets at play. | ||
| /// In this scenario, the [Window.viewInsets.bottom] will be 0, and the | ||
| /// [Window.padding.bottom] and [Window.viewPadding.bottom] will be some | ||
| /// positive number specified by the OS: |
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.
uber-nit: I wonder if s/OS/platform/ might be more accurate to account for things like web vs desktop etc.
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.
These docs are going to be removed.
lib/stub_ui/lib/src/ui/window.dart
Outdated
| /// ╲▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁╱ _____________________________________ | ||
| /// ``` | ||
| /// | ||
| /// Whereas when the keyboard is showing, the viewPadding and padding will be |
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.
nit: starting with 'Whereas' seems wrong since there's no comparison within the sentence.
| // keyboard height. We also eliminate any bottom safe-area padding since they keyboard 'consumes' | ||
| // the home indicator widget. | ||
| // keyboard height. The Dart side will compute a value accounting for the keyboard-consuming | ||
| // bottom padding. |
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.
Consider re-wording as: "The framework is responsible for computing a value accounting for keyboard-consuming bottom padding." since, in theory it's possible for another framework to be written on top of the engine.
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.
This is done in dart:ui though, not the framework.
lib/stub_ui/lib/src/ui/window.dart
Outdated
| /// ┃ ┃ _____________________________________ | ||
| /// ┃ ━━━━━━━━ ┃ viewPadding.bottom == padding.bottom | ||
| /// ╲▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁╱ _____________________________________ | ||
| /// ``` |
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.
ASCII art looks unprofessional, we should use real diagrams. (I believe we have some now yes?)
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.
This was meant to be removed
|
Tests? |
|
Assuming the documentation looks professional and the feature is tested, I have no objections. I defer to someone else for detailed review. |
|
Added tests. |
lib/stub_ui/lib/src/ui/window.dart
Outdated
| /// design applications. | ||
| WindowPadding get viewInsets => WindowPadding.zero; | ||
|
|
||
| WindowPadding get viewPadding => _viewPadding; |
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.
Why not just return WindowPadding.zero like viewInsets above?
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.
Done
lib/stub_ui/lib/src/ui/window.dart
Outdated
| /// design applications. | ||
| WindowPadding get viewInsets => WindowPadding.zero; | ||
|
|
||
| WindowPadding get viewPadding => _viewPadding; |
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.
Doc comment?
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.
stub_ui is going to have all its docs stripped.
lib/ui/window.dart
Outdated
| /// padding when visible. | ||
| /// | ||
| /// The [Window.viewInsets] are the physical pixels into which the operating | ||
| /// system may place system UI, such as the keyboard, which would fully obscure |
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.
may place or did place? In your diagram it looks like this only has a value != 0 when the keyboard is actually up and the screen is obscured.
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.
This was existing documentation. Maybe better to say "the system reserves for system UI"?
| /// any content drawn in that area. | ||
| /// | ||
| /// The [Window.viewPadding] are the physical pixels on each side of the display | ||
| /// that may be partially obscured by system UI or by physical intrusions into |
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.
It is not really clear what system UI affects the viewInsets and what the viewPadding. This makes it hard to understand what the difference between the two really is.
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.
Added some prose for this.
lib/ui/window.dart
Outdated
| /// e.g. if you wish to draw a widget at the center of the screen with respect | ||
| /// to the iPhone "safe area" regardless of whether the keyboard is showing. | ||
| /// | ||
| /// Clients that want to position elements or detect gestures relative to the |
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.
Not sure what this paragraph is saying?
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.
Rewrote it entirely.
goderbauer
left a comment
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.
LGTM
lib/ui/window.dart
Outdated
| /// represents the system keyboard, which can cover over the bottom view | ||
| /// padding when visible. | ||
| /// | ||
| /// The [Window.viewInsets] are the physical pixels into which the operating |
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.
grammar: into which the OS reserves for system UI?
lib/ui/window.dart
Outdated
| /// phone. Unlike the insets, these areas may have portions that show the user | ||
| /// application painted pixels without being obscured, such as a notch at the | ||
| /// top of a phone that covers only a subset of the area. Insets, on the other | ||
| /// hand, the insets either partially or fully obscured, such as as opaque |
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.
Insets, on the other hand, the insets <- is something missing here?
|
Updated docs. I'll hold off on merging this until the engine has rolled into the framework - autoroller is backed up by a few days now. |
|
Infra failure was a flake. Going to submit this on red (failing host test is expected because of framework updates needed). |
flutter/engine@f867609...a32df2c git log f867609..a32df2c --no-merges --oneline a32df2c Roll src/third_party/skia da95a75be1dd..c4fec06e5a3b (1 commits) (flutter/engine#9154) 79c6ce1 Preserve safe area (flutter/engine#8848) cbef680 Roll src/third_party/skia b9658153032a..da95a75be1dd (2 commits) (flutter/engine#9153) The AutoRoll server is located here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+/master/autoroll/README.md If the roll is causing failures, please contact the current sheriff ([email protected]), and stop the roller if necessary.
Preserve safe area on Window regardless of insets.
Addresses flutter/flutter#29941
On iOS today, we end up losing the system safe area dimension when the keyboard is visible. This works out for most cases, but some framework consumers still want to know the bottom padding value even if the keyboard is visible.
This is meant to be a non-breaking change that adds additional information to the window for that case. A subsequent patch to the framework will pump this through MediaQuery and look at usages for
SafeAreaandScaffoldetc.