-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Fix handling of safe-area padding in modal bottom sheets #121588
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix handling of safe-area padding in modal bottom sheets #121588
Conversation
gnprice
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.
Thanks! This looks like a good fix. Questions below about the docs.
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.
Is there a way to word this that provides more of a high-level story for what this field means?
In the existing version, I feel like I have that for the "true" case, but not for the "false" case. I don't really understand what "exposed to the top padding" or "un-exposed" etc. means; as best I understand what MediaQuery.removePadding actually does, I'm not seeing how "exposed" is the right verb for it.
Modulo that, I think this could look something like:
/// Whether to avoid system intrusions on the top, left, and right.
///
/// If true, a [SafeArea] is used in order to keep the bottom sheet away from
/// system intrusions at the top, left, and right sides of the screen.
///
/// If false, [??? I don't really understand what the purpose of the `removeTop: true`
/// is, so I'm not sure how to write this paragraph.]
///
/// In either case, the bottom sheet extends all the way to the bottom of
/// the screen, including any system intrusions.
///
/// The default is false.Some of the phrasing there, like "avoid system intrusions", is borrowed from the SafeArea docs.
A related question: in what sort of situation would a developer want to set this to true, or to leave it at its default of false?
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.
[??? I don't really understand what the purpose of the
removeTop: trueis, so I'm not sure how to write this paragraph.]
I'm not sure about this either. 🤔 The PR that added useSafeArea is #107140, and its description links to #39205 (comment) as the motivation. That comment describes a use case I hadn't considered:
In this case, the scrollable ModalBottomSheet has a pinned AppBar at the top, and so expected to fill the status bar space.
Then in a comment shortly after (#39205 (comment)):
It's a really interesting use case! The bottomsheet actually expands as it scrolls, and then the sheet/appbar kind of 'docks' with the top of the screen when it reaches it.
For that use case, I see why you'd want to decline ModalBottomSheetRoute's offer to insert a SafeArea: that SafeArea would prevent the sheet, and so its built-in app bar, from "docking" / extending all the way to the top of the screen, through the inset / system intrusion there.
But the MediaQuery.removePadding with removeTop isn't necessary to accomplish that, and in fact (to me) it looks like an obstacle to nicely handling the top inset. The sheet extends up through the top inset, but the sheet's interactive content still needs to render outside the top inset. An app bar normally handles that by padding the top inset with a blank portion of its surface, but this app bar can only guess at how much padding to use, since its ambient MediaQueryData.padding.top will be zero instead of the actual unconsumed height of the top inset.
|
(Continuing from the subthread #121588 (comment):) It looks like the origin of that I think the idea there was that the route's layout was taking care of adding padding as needed to keep the child away from system intrusions, and so when it adds that padding it should account for it in an adjusted
Yeah. If the |
|
In fact, looking back at that thread #39205, here's something I notice: there are several people showing workarounds that basically are there to defeat the
So I wonder if in fact the In that case, the @Piinks, as the voice of that customer at #39205 (comment) with the interesting bottomsheet use case: does that seem like potentially the right answer to you? (Meanwhile this whole subthread is about the |
|
Hey @gnprice!
TBH, I do not recall. I think your analysis makes sense though. I would say let's try it and run the internal test suite. That will surface the customer case (if it still exists) and we can take a closer look at it. |
a6f7cd0 to
fbb6ad7
Compare
useSafeArea: true|
Cool! I've just filed #121752 for the problematic |
gnprice
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! Thanks for the fix.
|
Thanks for the review! |
hannah-hyj
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
|
Can you update this PR's description about what's changing. Mention removing bottom when useSafeArea is true and the MediaQuery.removePadding issue when useSafeArea is false |
|
Thanks for the review! Done. |
|
It looks like Google testing failed. @Hangyujin are you able to take a look at what the failures were? One thing I'm curious about is whether the failures are in the case of But I think both of the fixes are good fixes, so in any event it'd be good to understand the nature of the failures. |
|
It looks like the test failure happened when I'd suggest separate these two fixes and land the |
Sure, makes sense! Just sent #122118 for the |
Fixes #121554.
Fixes #121752.
This makes these changes to how
useSafeAreaworks in theModalBottomSheetRouteclass and its wrappershowModalBottomSheet:useSafeArea: true, the addedSafeAreanow hasbottom: false, to prevent a gap from appearing between the bottom edge of the sheet and the bottom edge of the screen, across the system intrusion there. (This is the fix for ModalBottomSheetRoute:useSafeAreaputs gap below sheet #121554.)useSafeArea: false, there is no longer aMediaQuery.removePaddingwithremoveTop: true. This was preventing the sheet's content from accurately padding the system intrusion at the top, when desired. (This is the fix for ModalBottomSheetRoute: Content can't consume top notch withSafeArea#121752.)Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.