Skip to content

Commit 78cf9e5

Browse files
committed
msglist: Show channel name and topic name on two rows
This will eventually be superseded by #1039, so we should keep the implementation as simple as possible for now. The two-line app bar idea comes from the legacy mobile app. This gives us a place to show the topic visibility policy on the app bar. References: https://github.com/zulip/zulip-mobile/blob/a115df1f71c9dc31e9b41060a8d57b51c017d786/src/title/TitleStream.js#L113-L141 https://github.com/zulip/zulip-mobile/blob/a115df1f71c9dc31e9b41060a8d57b51c017d786/src/styles/navStyles.js#L5-L18 Signed-off-by: Zixuan James Li <[email protected]>
1 parent 6db70db commit 78cf9e5

File tree

2 files changed

+46
-7
lines changed

2 files changed

+46
-7
lines changed

lib/widgets/message_list.dart

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,8 @@ class _MessageListPageState extends State<MessageListPage> implements MessageLis
262262

263263
List<Widget>? actions;
264264
if (narrow case TopicNarrow(:final streamId)) {
265+
// The helper [_getEffectiveCenterTitle] relies on the fact that we
266+
// have at most one action here.
265267
(actions ??= []).add(IconButton(
266268
icon: const Icon(ZulipIcons.message_feed),
267269
tooltip: zulipLocalizations.channelFeedButtonTooltip,
@@ -314,7 +316,6 @@ class MessageListAppBarTitle extends StatelessWidget {
314316

315317
Widget _buildStreamRow(BuildContext context, {
316318
ZulipStream? stream,
317-
required String text,
318319
}) {
319320
// A null [Icon.icon] makes a blank space.
320321
final icon = (stream != null) ? iconDataForStream(stream) : null;
@@ -327,10 +328,42 @@ class MessageListAppBarTitle extends StatelessWidget {
327328
children: [
328329
Icon(size: 16, icon),
329330
const SizedBox(width: 4),
330-
Flexible(child: Text(text)),
331+
Flexible(child: Text(stream?.name ?? '(unknown stream)')),
331332
]);
332333
}
333334

335+
Widget _buildTopicRow(BuildContext context, {
336+
required ZulipStream? stream,
337+
required String topic,
338+
}) {
339+
return Text(topic, style: const TextStyle(
340+
fontSize: 13,
341+
).merge(weightVariableTextStyle(context)));
342+
}
343+
344+
// TODO(upstream): provide an API for this
345+
// Adapted from [AppBar._getEffectiveCenterTitle].
346+
bool _getEffectiveCenterTitle(ThemeData theme) {
347+
bool platformCenter() {
348+
switch (theme.platform) {
349+
case TargetPlatform.android:
350+
case TargetPlatform.fuchsia:
351+
case TargetPlatform.linux:
352+
case TargetPlatform.windows:
353+
return false;
354+
case TargetPlatform.iOS:
355+
case TargetPlatform.macOS:
356+
// We rely on the fact that there is at most one action
357+
// on the message list app bar, so that the expression returned
358+
// in the original helper, `actions == null || actions!.length < 2`,
359+
// always evaluates to `true`:
360+
return true;
361+
}
362+
}
363+
364+
return theme.appBarTheme.centerTitle ?? platformCenter();
365+
}
366+
334367
@override
335368
Widget build(BuildContext context) {
336369
final zulipLocalizations = ZulipLocalizations.of(context);
@@ -348,14 +381,20 @@ class MessageListAppBarTitle extends StatelessWidget {
348381
case ChannelNarrow(:var streamId):
349382
final store = PerAccountStoreWidget.of(context);
350383
final stream = store.streams[streamId];
351-
final streamName = stream?.name ?? '(unknown channel)';
352-
return _buildStreamRow(context, stream: stream, text: streamName);
384+
return _buildStreamRow(context, stream: stream);
353385

354386
case TopicNarrow(:var streamId, :var topic):
387+
final theme = Theme.of(context);
355388
final store = PerAccountStoreWidget.of(context);
356389
final stream = store.streams[streamId];
357-
final streamName = stream?.name ?? '(unknown channel)';
358-
return _buildStreamRow(context, stream: stream, text: "$streamName > $topic");
390+
final centerTitle = _getEffectiveCenterTitle(theme);
391+
return Column(
392+
crossAxisAlignment: centerTitle ? CrossAxisAlignment.center
393+
: CrossAxisAlignment.start,
394+
children: [
395+
_buildStreamRow(context, stream: stream),
396+
_buildTopicRow(context, stream: stream, topic: topic),
397+
]);
359398

360399
case DmNarrow(:var otherRecipientIds):
361400
final store = PerAccountStoreWidget.of(context);

test/widgets/message_list_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ void main() {
725725
).length.equals(1);
726726
check(find.descendant(
727727
of: find.byType(MessageListAppBarTitle),
728-
matching: find.text('${channel.name} > new topic')).evaluate()
728+
matching: find.text('new topic')).evaluate()
729729
).length.equals(1);
730730
});
731731
});

0 commit comments

Comments
 (0)