-
Notifications
You must be signed in to change notification settings - Fork 249
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
msglist [nfc]: Remove one Center
widget (because no-op); comment to explain another
#1042
Conversation
lib/widgets/message_list.dart
Outdated
@@ -467,6 +467,7 @@ class _MessageListState extends State<MessageList> with PerAccountStoreAwareStat | |||
// will have a `MediaQuery.removePadding` with `removeBottom: true`. | |||
bottom: false, | |||
|
|||
// (center horizontally on wide screens; a no-op in the vertical direction) |
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.
Do you have a screenshot when that happens? I wasn't able to reproduce the effect if I remove Center
on my devices:
Maybe I looked at the wrong place? Oh! I see, I can reproduce that when the compose box is absent in the combined feed, because in that case the message list is the only child in the Column
on MessageListPage
, and the message list doesn't fill horizontally like ComposeBox
does, if without Center
.
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.
If we remove the Center
here, and keep the one on MessageListPage
, the combined feed looks fine. Because Center
specifically deals with sizing the widget within a Scaffold
, it might be clearer to remove the Center
here, and comment on the Center
on MessageListPage
.
SizedBox.expand
might be a good alternative, because Column
can center its children.
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.
Oh, I got some reasoning wrong 🙂:
msglist [nfc]: Remove no-op Center widget in _MessageListPageState
The Center's child is a Column with the message list and possibly a
compose box. That Column expresses that it wants to fill all the
available space […]
I think this is true in the vertical direction (mainAxisSize
is at its default, MainAxisSize.max
) but not the horizontal direction. I can make it not fill all the available horizontal space by just replacing its children with colored boxes:
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.
If we remove the
Center
here, and keep the one onMessageListPage
, the combined feed looks fine.
Agreed; I see this too.
Because
Center
specifically deals with sizing the widget within aScaffold
, it might be clearer to remove theCenter
here, and comment on theCenter
onMessageListPage
.
(Did you mean positioning instead of sizing?)
There's other logic that also positions the message list horizontally on the screen, with the assumption that it's working with the full width of the screen. See in _MessageListState.build
:
// Pad the left and right insets, for small devices in landscape.
return SafeArea(
As long as that's done in _MessageListState.build
, I think the other positioning logic—the Center
—belongs there too, instead of somewhere farther away. And that SafeArea
can't move outward because it would prevent the compose box from stretching to the left/right edges of the screen, and we don't have a design to make that look OK:
I also think the layout is easier to reason about if the SafeArea
's padding is always positioned exactly on the device insets—
—than if the SafeArea
's padding is sometimes not positioned on the device insets:
especially if the insets aren't symmetric (though I don't have a device to demonstrate that). (In these screenshots I've changed the max-width from 760 to 500 so I can demonstrate using my phone.)
This basically means the Center
should be a descendant of the SafeArea
, and the SafeArea
should cover the full width of the screen.
13e1284
to
d7e5964
Compare
Thanks for the review! Revision pushed (atop #1290 for the sake of CI), and see my reply above: #1042 (comment) |
d7e5964
to
568e959
Compare
(Pushed another tweak or two—I think I'm finished for this evening though 😄) |
Thanks! This all make sense to me except just this part from the commit message:
I was confused at first as I read #1042 (comment). Maybe it can be rephrased so that it is clearer that the children taking all the horizontal space is necessary. |
568e959
to
2cc8ebc
Compare
Thanks for the review! Revision pushed,
Ah, yeah: rather than what I said at #1042 (comment), I think the point I'd like to make is: in Having gone and read those details, though, we can conclude that the - builder: (BuildContext context) => Center(
- child: Column(children: [
+ builder: (BuildContext context) => Column(
+ // Children are expected to take the full horizontal space
+ // and handle the horizontal device insets.
+ children: [ —should help readers understand more quickly that something like the removed For the reason that the children need to fill the full horizontal width, I've updated a commit message: It turns out that the Column always takes all horizontal space, too;
the message-list and compose-box widgets both stretch to the full
- screen width. This is appropriate because they want to handle the
- horizontal device insets in separate ways: the former by keeping
+ screen width. This is appropriate because they need to handle the
+ horizontal device insets in different ways: the former by keeping
visible UI outside the insets; the latter by filling the insets with
padding. So the Center is a no-op in the horizontal direction, too. |
Cool, thanks for the update! Marked for Greg's review. |
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 to you both for the clarifications!
This generally all looks good; a couple of tweaks below.
lib/widgets/message_list.dart
Outdated
// Horizontally, on wide screens, this grows the SafeArea | ||
// to position its padding over the device insets and centers content. |
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:
// Horizontally, on wide screens, this grows the SafeArea | |
// to position its padding over the device insets and centers content. | |
// Horizontally, on wide screens, this Center grows the SafeArea | |
// to position its padding over the device insets and centers content. |
That makes it a bit clearer what "this" is meant to refer to.
lib/widgets/message_list.dart
Outdated
/// Takes the full screen width, | ||
/// keeping the message list and scroll-to-bottom button | ||
/// out of the horizontal insets with transparent [SafeArea] padding. | ||
/// When there is no [ComposeBox], | ||
/// adds transparent [SliverSafeArea] and [SafeArea] padding | ||
/// to the message-list content and the scroll-to-bottom button, respectively. |
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 feels a bit too specific about how it does what it does, in the sort of way that's at risk of becoming wrong over time. How about this?
/// Takes the full screen width, | |
/// keeping the message list and scroll-to-bottom button | |
/// out of the horizontal insets with transparent [SafeArea] padding. | |
/// When there is no [ComposeBox], | |
/// adds transparent [SliverSafeArea] and [SafeArea] padding | |
/// to the message-list content and the scroll-to-bottom button, respectively. | |
/// Takes the full screen width, keeping its contents | |
/// out of the horizontal insets with transparent [SafeArea] padding. | |
/// When there is no [ComposeBox], also takes responsibility | |
/// for dealing with the bottom inset. |
2cc8ebc
to
518df26
Compare
Thanks for the review! Revision pushed. |
The Center's child is a Column with the message list and possibly a compose box. Since the Column has the default MainAxisSize.max, it occupies all available vertical space, so the Center is a no-op on the vertical axis. (If an element occupies all available space on an axis, it has only one possible position on that axis, so the Center can't affect its position.) It turns out that the Column always takes all horizontal space, too; the message-list and compose-box widgets both stretch to the full screen width. This is appropriate because they need to handle the horizontal device insets in different ways: the former by keeping visible UI outside the insets; the latter by filling the insets with padding. So the Center is a no-op in the horizontal direction, too. It's a relic from the very early prototype in late 2022 (see commit b22ef67); remove it. Also, with some new comments and dartdoc, make it clearer that the Column takes the full screen width.
…button (We're already doing what the new comment says.)
Thanks! Looks good; merging. |
518df26
to
4c04d07
Compare
No description provided.