Skip to content

msglist [nfc]: Remove one Center widget (because no-op); comment to explain another #1042

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

Merged
merged 3 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/widgets/compose_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ class _ComposeBoxContainer extends StatelessWidget {
};

// TODO(design): Maybe put a max width on the compose box, like we do on
// the message list itself
// the message list itself; if so, remember to update ComposeBox's dartdoc.
return Container(width: double.infinity,
decoration: BoxDecoration(
border: Border(top: BorderSide(color: designVariables.borderBar))),
Expand Down Expand Up @@ -1275,6 +1275,10 @@ class _ErrorBanner extends StatelessWidget {
}
}

/// The compose box.
///
/// Takes the full screen width, covering the horizontal insets with its surface.
/// Also covers the bottom inset with its surface.
class ComposeBox extends StatefulWidget {
ComposeBox({super.key, required this.narrow})
: assert(ComposeBox.hasComposeBox(narrow));
Expand Down
28 changes: 21 additions & 7 deletions lib/widgets/message_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,11 @@ class _MessageListPageState extends State<MessageListPage> implements MessageLis
// we matched to the Figma in 21dbae120. See another frame, which uses that:
// https://www.figma.com/file/1JTNtYo9memgW7vV6d0ygq/Zulip-Mobile?node-id=147%3A9088&mode=dev
body: Builder(
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.
// The bottom inset should be handled by the last child only.
children: [
MediaQuery.removePadding(
// Scaffold knows about the app bar, and so has run this
// BuildContext, which is under `body`, through
Expand All @@ -315,7 +318,7 @@ class _MessageListPageState extends State<MessageListPage> implements MessageLis
))),
if (ComposeBox.hasComposeBox(narrow))
ComposeBox(key: _composeBoxKey, narrow: narrow)
]))));
])));
}
}

Expand Down Expand Up @@ -432,6 +435,12 @@ const _kShortMessageHeight = 80;
// previous batch.
const kFetchMessagesBufferPixels = (kMessageListFetchBatchSize / 2) * _kShortMessageHeight;

/// The message list.
///
/// 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.
class MessageList extends StatefulWidget {
const MessageList({super.key, required this.narrow, required this.onNarrowChanged});

Expand Down Expand Up @@ -525,12 +534,15 @@ class _MessageListState extends State<MessageList> with PerAccountStoreAwareStat
// Pad the left and right insets, for small devices in landscape.
return SafeArea(
// Don't let this be the place we pad the bottom inset. When there's
// no compose box, we want to let the message-list content pad it.
// no compose box, we want to let the message-list content
// and the scroll-to-bottom button avoid it.
// TODO(#311) Remove as unnecessary if we do a bottom nav.
// The nav will pad the bottom inset, and an ancestor of this widget
// will have a `MediaQuery.removePadding` with `removeBottom: true`.
bottom: false,

// Horizontally, on wide screens, this Center grows the SafeArea
// to position its padding over the device insets and centers content.
child: Center(
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 760),
Expand All @@ -543,7 +555,9 @@ class _MessageListState extends State<MessageList> with PerAccountStoreAwareStat
bottom: 0,
right: 0,
// TODO(#311) SafeArea shouldn't be needed if we have a
// bottom nav. That will pad the bottom inset.
// bottom nav; that will pad the bottom inset. Remove it,
// and the mention of bottom-inset handling in
// MessageList's dartdoc.
child: SafeArea(
child: ScrollToBottomButton(
scrollController: scrollController,
Expand Down Expand Up @@ -594,8 +608,8 @@ class _MessageListState extends State<MessageList> with PerAccountStoreAwareStat
}));

if (!ComposeBox.hasComposeBox(widget.narrow)) {
// TODO(#311) If we have a bottom nav, it will pad the bottom
// inset, and this shouldn't be necessary
// TODO(#311) If we have a bottom nav, it will pad the bottom inset,
// and this can be removed; also remove mention in MessageList dartdoc
sliver = SliverSafeArea(sliver: sliver);
}

Expand Down