Skip to content
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

Merged
merged 3 commits into from
Jan 23, 2025

Conversation

chrisbobbe
Copy link
Collaborator

No description provided.

@chrisbobbe chrisbobbe added the maintainer review PR ready for review by Zulip maintainers label Nov 1, 2024
@chrisbobbe chrisbobbe requested a review from PIG208 November 1, 2024 22:59
@@ -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)
Copy link
Member

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:

Linux

image

Android

1000015248

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.

Details

image

Copy link
Member

@PIG208 PIG208 Nov 5, 2024

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.

Copy link
Collaborator Author

@chrisbobbe chrisbobbe Jan 18, 2025

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:

Copy link
Collaborator Author

@chrisbobbe chrisbobbe Jan 18, 2025

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.

Agreed; I see this too.

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.

(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:

image

I also think the layout is easier to reason about if the SafeArea's padding is always positioned exactly on the device insets—

FBD09C7B-5A63-4610-97E4-58F88C3A342E

—than if the SafeArea's padding is sometimes not positioned on the device insets:

7614EA90-FCCA-4676-9C4F-AE6BBB85A522

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.

@chrisbobbe chrisbobbe force-pushed the pr-msglist-center-widgets-nfc branch from 13e1284 to d7e5964 Compare January 18, 2025 02:35
@chrisbobbe
Copy link
Collaborator Author

chrisbobbe commented Jan 18, 2025

Thanks for the review! Revision pushed (atop #1290 for the sake of CI), and see my reply above: #1042 (comment)

@chrisbobbe chrisbobbe force-pushed the pr-msglist-center-widgets-nfc branch from d7e5964 to 568e959 Compare January 18, 2025 02:45
@chrisbobbe
Copy link
Collaborator Author

(Pushed another tweak or two—I think I'm finished for this evening though 😄)

@PIG208
Copy link
Member

PIG208 commented Jan 18, 2025

Thanks! This all make sense to me except just this part from the 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.

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.

@chrisbobbe chrisbobbe force-pushed the pr-msglist-center-widgets-nfc branch from 568e959 to 2cc8ebc Compare January 21, 2025 23:57
@chrisbobbe
Copy link
Collaborator Author

Thanks for the review! Revision pushed,

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.

Ah, yeah: rather than what I said at #1042 (comment), I think the point I'd like to make is: in main, you can't tell just by looking locally at the Column that it takes the full horizontal width. You have to read details of its children, which are distant by many lines of code or in a different file. For example, the Column doesn't have CrossAxisAlignment.stretch; if it did, it would be clearer that the Center is a no-op in the horizontal direction.

Having gone and read those details, though, we can conclude that the Column does in fact fill the full horizontal width (thanks to the Center in the message list, which is always present), and so it's a no-op and can be removed. A new comment I add in the PR—

-        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 Center doesn't need to be added back again.

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.

@PIG208 PIG208 added integration review Added by maintainers when PR may be ready for integration and removed maintainer review PR ready for review by Zulip maintainers labels Jan 22, 2025
@PIG208 PIG208 assigned gnprice and unassigned PIG208 Jan 22, 2025
@PIG208
Copy link
Member

PIG208 commented Jan 22, 2025

Cool, thanks for the update! Marked for Greg's review.

@chrisbobbe chrisbobbe requested a review from gnprice January 22, 2025 21:40
Copy link
Member

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

Comment on lines 556 to 545
// Horizontally, on wide screens, this grows the SafeArea
// to position its padding over the device insets and centers content.
Copy link
Member

Choose a reason for hiding this comment

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

nit:

Suggested change
// 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.

Comment on lines 450 to 455
/// 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.
Copy link
Member

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?

Suggested change
/// 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.

@chrisbobbe chrisbobbe force-pushed the pr-msglist-center-widgets-nfc branch from 2cc8ebc to 518df26 Compare January 23, 2025 19:56
@chrisbobbe
Copy link
Collaborator Author

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

gnprice commented Jan 23, 2025

Thanks! Looks good; merging.

@gnprice gnprice force-pushed the pr-msglist-center-widgets-nfc branch from 518df26 to 4c04d07 Compare January 23, 2025 21:26
@gnprice gnprice merged commit 4c04d07 into zulip:main Jan 23, 2025
1 check passed
@chrisbobbe chrisbobbe deleted the pr-msglist-center-widgets-nfc branch January 24, 2025 03:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration review Added by maintainers when PR may be ready for integration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants