Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@dnfield
Copy link
Contributor

@dnfield dnfield commented May 4, 2019

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 SafeArea and Scaffold etc.

@dnfield dnfield requested a review from cbracken May 4, 2019 14:27
Copy link
Member

@cbracken cbracken left a 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.

@dnfield
Copy link
Contributor Author

dnfield commented May 7, 2019

The build_and_test_host failure is expected, since this will require updates to the framework to account for the new property on Window.

@dnfield dnfield requested a review from Hixie May 7, 2019 13:43
@Hixie
Copy link
Contributor

Hixie commented May 7, 2019

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.

@dnfield
Copy link
Contributor Author

dnfield commented May 7, 2019

@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....

@dnfield
Copy link
Contributor Author

dnfield commented May 9, 2019

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.

@Hixie
Copy link
Contributor

Hixie commented May 13, 2019

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.

@dnfield
Copy link
Contributor Author

dnfield commented May 13, 2019

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.

@gspencergoog
Copy link
Contributor

gspencergoog commented May 13, 2019

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.

@dnfield
Copy link
Contributor Author

dnfield commented May 13, 2019

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?

@Hixie
Copy link
Contributor

Hixie commented May 13, 2019

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.

dnfield added a commit to dnfield/assets-for-api-docs that referenced this pull request May 14, 2019
/// 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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: operating

Copy link
Member

@cbracken cbracken left a 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;
Copy link
Member

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.

/// 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:
Copy link
Member

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.

Copy link
Contributor Author

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.

/// ╲▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁╱ _____________________________________
/// ```
///
/// Whereas when the keyboard is showing, the viewPadding and padding will be
Copy link
Member

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.
Copy link
Member

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.

Copy link
Contributor Author

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.

/// ┃ ┃ _____________________________________
/// ┃ ━━━━━━━━ ┃ viewPadding.bottom == padding.bottom
/// ╲▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁╱ _____________________________________
/// ```
Copy link
Contributor

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?)

Copy link
Contributor Author

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

@Hixie
Copy link
Contributor

Hixie commented May 20, 2019

Tests?

@Hixie
Copy link
Contributor

Hixie commented May 20, 2019

Assuming the documentation looks professional and the feature is tested, I have no objections. I defer to someone else for detailed review.

@dnfield
Copy link
Contributor Author

dnfield commented May 22, 2019

Added tests.

@dnfield dnfield requested review from cbracken and goderbauer May 28, 2019 20:39
/// design applications.
WindowPadding get viewInsets => WindowPadding.zero;

WindowPadding get viewPadding => _viewPadding;
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

/// design applications.
WindowPadding get viewInsets => WindowPadding.zero;

WindowPadding get viewPadding => _viewPadding;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doc comment?

Copy link
Contributor Author

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.

/// 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
Copy link
Member

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.

Copy link
Contributor Author

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
Copy link
Member

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.

Copy link
Contributor Author

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.

/// 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
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rewrote it entirely.

Copy link
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

/// 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
Copy link
Member

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?

/// 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
Copy link
Member

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?

@dnfield
Copy link
Contributor Author

dnfield commented May 30, 2019

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.

@dnfield
Copy link
Contributor Author

dnfield commented May 31, 2019

Infra failure was a flake. Going to submit this on red (failing host test is expected because of framework updates needed).

@dnfield dnfield merged commit 79c6ce1 into flutter:master May 31, 2019
@dnfield dnfield deleted the media_query branch May 31, 2019 16:24
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 31, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 31, 2019
engine-flutter-autoroll added a commit to flutter/flutter that referenced this pull request May 31, 2019
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.
huqiuser pushed a commit to huqiuser/engine that referenced this pull request Jun 12, 2019
Preserve safe area on Window regardless of insets.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants