Skip to content

Commit 003a523

Browse files
committed
msglist: Apply subscription color to StreamMessageRecipientHeader
Also bring back contrasting color to text.
1 parent c7a0895 commit 003a523

File tree

3 files changed

+34
-8
lines changed

3 files changed

+34
-8
lines changed

lib/widgets/message_list.dart

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,13 @@ class StreamMessageRecipientHeader extends StatelessWidget {
548548

549549
final stream = store.streams[message.streamId];
550550
final topic = message.subject;
551+
final swatch = store.subscriptions[message.streamId]?.colorSwatch()
552+
?? _kFallbackStreamColorSwatch;
553+
final contrastingColor =
554+
(ThemeData.estimateBrightnessForColor(swatch.barBackground) == Brightness.dark)
555+
? Colors.white
556+
: Colors.black;
557+
final textStyle = TextStyle(color: contrastingColor);
551558

552559
final streamWidget = (showStream)
553560
? GestureDetector(
@@ -557,13 +564,14 @@ class StreamMessageRecipientHeader extends StatelessWidget {
557564
child: Row(children: [
558565
const SizedBox(width: 16),
559566
// TODO globe/lock icons for web-public and private streams
560-
Text(stream?.name ?? message.displayRecipient), // TODO(log) if missing
567+
Text(stream?.name ?? message.displayRecipient, // TODO(log) if missing
568+
style: textStyle),
561569
Padding(
562570
// Figma has 5px horizontal padding around an 8px wide icon.
563571
// Icon is 16px wide here so horizontal padding is 1px.
564572
padding: const EdgeInsets.symmetric(horizontal: 1),
565573
child: Icon(size: 16,
566-
color: const HSLColor.fromAHSL(0.60, 0, 0, 0).toColor(),
574+
color: contrastingColor.withAlpha(154), // 60%
567575
ZulipIcons.chevron_right)),
568576
]))
569577
: const SizedBox(width: 16);
@@ -573,7 +581,7 @@ class StreamMessageRecipientHeader extends StatelessWidget {
573581
MessageListPage.buildRoute(context: context,
574582
narrow: TopicNarrow.ofMessage(message))),
575583
child: ColoredBox(
576-
color: _kStreamMessageBorderColor,
584+
color: swatch.barBackground,
577585
child: Row(mainAxisAlignment: MainAxisAlignment.start, children: [
578586
// TODO(#282): Long stream name will break layout; find a fix.
579587
streamWidget,
@@ -584,18 +592,17 @@ class StreamMessageRecipientHeader extends StatelessWidget {
584592
child: Text(topic,
585593
// TODO: Give a way to see the whole topic (maybe a
586594
// long-press interaction?)
587-
overflow: TextOverflow.ellipsis))),
595+
overflow: TextOverflow.ellipsis,
596+
style: textStyle))),
588597
// TODO topic links?
589598
// Then web also has edit/resolve/mute buttons. Skip those for mobile.
590599
RecipientHeaderDate(message: message,
591-
color: const HSLColor.fromAHSL(0.75, 0, 0, 0.15).toColor()),
600+
color: contrastingColor.withAlpha(102)), // 40%
592601
const SizedBox(width: 16),
593602
])));
594603
}
595604
}
596605

597-
final _kStreamMessageBorderColor = const HSLColor.fromAHSL(1, 0, 0, 0.88).toColor();
598-
599606
class DmRecipientHeader extends StatelessWidget {
600607
const DmRecipientHeader({super.key, required this.message});
601608

test/flutter_checks.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ extension ClipboardDataChecks on Subject<ClipboardData> {
1616
Subject<String?> get text => has((d) => d.text, 'text');
1717
}
1818

19+
extension ColoredBoxChecks on Subject<ColoredBox> {
20+
Subject<Color?> get color => has((d) => d.color, 'color');
21+
}
22+
1923
extension GlobalKeyChecks<T extends State<StatefulWidget>> on Subject<GlobalKey<T>> {
2024
Subject<BuildContext?> get currentContext => has((k) => k.currentContext, 'currentContext');
2125
Subject<Widget?> get currentWidget => has((k) => k.currentWidget, 'currentWidget');

test/widgets/message_list_test.dart

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@ void main() {
4141
int? messageCount,
4242
List<Message>? messages,
4343
List<ZulipStream>? streams,
44+
List<Subscription>? subscriptions,
4445
UnreadMessagesSnapshot? unreadMsgs,
4546
}) async {
4647
addTearDown(testBinding.reset);
48+
streams ??= subscriptions;
4749
await testBinding.globalStore.add(eg.selfAccount, eg.initialSnapshot(
48-
streams: streams, unreadMsgs: unreadMsgs));
50+
streams: streams, subscriptions: subscriptions, unreadMsgs: unreadMsgs));
4951
store = await testBinding.globalStore.perAccount(eg.selfAccount.id);
5052
connection = store.connection as FakeApiConnection;
5153

@@ -232,6 +234,19 @@ void main() {
232234
check(findInMessageList('stream name')).length.equals(0);
233235
check(findInMessageList('topic name')).length.equals(1);
234236
});
237+
238+
testWidgets('color of recipient header background', (tester) async {
239+
final subscription = eg.subscription(stream, color: Colors.red.value);
240+
final swatch = subscription.colorSwatch();
241+
await setupMessageListPage(tester,
242+
messages: [message], subscriptions: [subscription]);
243+
await tester.pump();
244+
check(tester.widget<ColoredBox>(
245+
find.descendant(
246+
of: find.byType(StreamMessageRecipientHeader),
247+
matching: find.byType(ColoredBox),
248+
))).color.equals(swatch.barBackground);
249+
});
235250
});
236251

237252
testWidgets('show stream name from message when stream unknown', (tester) async {

0 commit comments

Comments
 (0)