Skip to content

Commit f48b9c0

Browse files
committed
compose_box [nfc]: Avoid inline checks on narrows.
This will later help ensure the exhaustiveness of similar checks performed on a Narrow. The change is motivated by the need to support new narrows. Signed-off-by: Zixuan James Li <[email protected]>
1 parent 4d0b8d9 commit f48b9c0

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

lib/widgets/compose_box.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,18 @@ class ComposeBox extends StatelessWidget {
958958
final GlobalKey<ComposeBoxController>? controllerKey;
959959
final Narrow narrow;
960960

961+
static bool hasComposeBox(Narrow narrow) {
962+
switch (narrow) {
963+
case CombinedFeedNarrow():
964+
return true;
965+
966+
case StreamNarrow():
967+
case TopicNarrow():
968+
case DmNarrow():
969+
return false;
970+
}
971+
}
972+
961973
@override
962974
Widget build(BuildContext context) {
963975
final narrow = this.narrow;

lib/widgets/message_list.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ class _MessageListPageState extends State<MessageListPage> implements MessageLis
130130
// if those details get complicated, refactor to avoid copying.
131131
// TODO(#311) If we have a bottom nav, it will pad the bottom
132132
// inset, and this should always be true.
133-
removeBottom: widget.narrow is! CombinedFeedNarrow,
133+
removeBottom: !ComposeBox.hasComposeBox(widget.narrow),
134134

135135
child: Expanded(
136136
child: MessageList(narrow: widget.narrow))),
@@ -361,7 +361,7 @@ class _MessageListState extends State<MessageList> with PerAccountStoreAwareStat
361361
return _buildItem(data, i);
362362
}));
363363

364-
if (widget.narrow is CombinedFeedNarrow) {
364+
if (ComposeBox.hasComposeBox(widget.narrow)) {
365365
// TODO(#311) If we have a bottom nav, it will pad the bottom
366366
// inset, and this shouldn't be necessary
367367
sliver = SliverSafeArea(sliver: sliver);
@@ -542,7 +542,7 @@ class RecipientHeader extends StatelessWidget {
542542
final message = this.message;
543543
return switch (message) {
544544
StreamMessage() => StreamMessageRecipientHeader(message: message,
545-
showStream: narrow is CombinedFeedNarrow),
545+
showStream: ComposeBox.hasComposeBox(narrow)),
546546
DmMessage() => DmRecipientHeader(message: message),
547547
};
548548
}

0 commit comments

Comments
 (0)