Skip to content

Commit 17019d4

Browse files
committed
theme: Compute colorSwatchFor when subscription is null
Looking into the design requirement a bit more, we initially fall back to this color because we didn't have the logic to generate channel colors: https://chat.zulip.org/#narrow/channel/48-mobile/topic/All.20channels.20screen.20-.20.23F832/near/1904009 This replaces the ad-hoc colors with generated colors based on a fallback base color. The base color we fall back to is still a placeholder. Ideally, we should pick a color for the unsubscribed streams, as shown in the Figma design linked in #188. That issue is out-of-scope for this, though. For now, it's sufficient to just remove the ad-hoc color on MessageListTheme. This way we don't have to reuse it in places where colors for unsubscribed streams are needed, namely the topic list.
1 parent 29cbf10 commit 17019d4

File tree

3 files changed

+25
-29
lines changed

3 files changed

+25
-29
lines changed

lib/widgets/message_list.dart

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ class MessageListTheme extends ThemeExtension<MessageListTheme> {
4646
unreadMarker: const HSLColor.fromAHSL(1, 227, 0.78, 0.59).toColor(),
4747

4848
unreadMarkerGap: Colors.white.withValues(alpha: 0.6),
49-
50-
// TODO(design) this seems ad-hoc; is there a better color?
51-
unsubscribedStreamRecipientHeaderBg: const Color(0xfff5f5f5),
5249
);
5350

5451
static final dark = MessageListTheme._(
@@ -66,9 +63,6 @@ class MessageListTheme extends ThemeExtension<MessageListTheme> {
6663
unreadMarker: const HSLColor.fromAHSL(0.75, 227, 0.78, 0.59).toColor(),
6764

6865
unreadMarkerGap: Colors.transparent,
69-
70-
// TODO(design) this is ad-hoc and untested; is there a better color?
71-
unsubscribedStreamRecipientHeaderBg: const Color(0xff0a0a0a),
7266
);
7367

7468
MessageListTheme._({
@@ -79,7 +73,6 @@ class MessageListTheme extends ThemeExtension<MessageListTheme> {
7973
required this.streamRecipientHeaderChevronRight,
8074
required this.unreadMarker,
8175
required this.unreadMarkerGap,
82-
required this.unsubscribedStreamRecipientHeaderBg,
8376
});
8477

8578
/// The [MessageListTheme] from the context's active theme.
@@ -99,7 +92,6 @@ class MessageListTheme extends ThemeExtension<MessageListTheme> {
9992
final Color streamRecipientHeaderChevronRight;
10093
final Color unreadMarker;
10194
final Color unreadMarkerGap;
102-
final Color unsubscribedStreamRecipientHeaderBg;
10395

10496
@override
10597
MessageListTheme copyWith({
@@ -110,7 +102,6 @@ class MessageListTheme extends ThemeExtension<MessageListTheme> {
110102
Color? streamRecipientHeaderChevronRight,
111103
Color? unreadMarker,
112104
Color? unreadMarkerGap,
113-
Color? unsubscribedStreamRecipientHeaderBg,
114105
}) {
115106
return MessageListTheme._(
116107
bgMessageRegular: bgMessageRegular ?? this.bgMessageRegular,
@@ -120,7 +111,6 @@ class MessageListTheme extends ThemeExtension<MessageListTheme> {
120111
streamRecipientHeaderChevronRight: streamRecipientHeaderChevronRight ?? this.streamRecipientHeaderChevronRight,
121112
unreadMarker: unreadMarker ?? this.unreadMarker,
122113
unreadMarkerGap: unreadMarkerGap ?? this.unreadMarkerGap,
123-
unsubscribedStreamRecipientHeaderBg: unsubscribedStreamRecipientHeaderBg ?? this.unsubscribedStreamRecipientHeaderBg,
124114
);
125115
}
126116

@@ -137,7 +127,6 @@ class MessageListTheme extends ThemeExtension<MessageListTheme> {
137127
streamRecipientHeaderChevronRight: Color.lerp(streamRecipientHeaderChevronRight, other.streamRecipientHeaderChevronRight, t)!,
138128
unreadMarker: Color.lerp(unreadMarker, other.unreadMarker, t)!,
139129
unreadMarkerGap: Color.lerp(unreadMarkerGap, other.unreadMarkerGap, t)!,
140-
unsubscribedStreamRecipientHeaderBg: Color.lerp(unsubscribedStreamRecipientHeaderBg, other.unsubscribedStreamRecipientHeaderBg, t)!,
141130
);
142131
}
143132
}
@@ -228,9 +217,8 @@ class _MessageListPageState extends State<MessageListPage> implements MessageLis
228217
case ChannelNarrow(:final streamId):
229218
case TopicNarrow(:final streamId):
230219
final subscription = store.subscriptions[streamId];
231-
appBarBackgroundColor = subscription != null
232-
? colorSwatchFor(context, subscription).barBackground
233-
: messageListTheme.unsubscribedStreamRecipientHeaderBg;
220+
appBarBackgroundColor =
221+
colorSwatchFor(context, subscription).barBackground;
234222
// All recipient headers will match this color; remove distracting line
235223
// (but are recipient headers even needed for topic narrows?)
236224
removeAppBarBottomBorder = true;
@@ -1054,24 +1042,15 @@ class StreamMessageRecipientHeader extends StatelessWidget {
10541042
// https://github.com/zulip/zulip-mobile/issues/5511
10551043
final store = PerAccountStoreWidget.of(context);
10561044
final designVariables = DesignVariables.of(context);
1045+
final messageListTheme = MessageListTheme.of(context);
10571046
final zulipLocalizations = ZulipLocalizations.of(context);
10581047

10591048
final streamId = message.conversation.streamId;
10601049
final topic = message.conversation.topic;
10611050

1062-
final messageListTheme = MessageListTheme.of(context);
1063-
1064-
final subscription = store.subscriptions[streamId];
1065-
final Color backgroundColor;
1066-
final Color iconColor;
1067-
if (subscription != null) {
1068-
final swatch = colorSwatchFor(context, subscription);
1069-
backgroundColor = swatch.barBackground;
1070-
iconColor = swatch.iconOnBarBackground;
1071-
} else {
1072-
backgroundColor = messageListTheme.unsubscribedStreamRecipientHeaderBg;
1073-
iconColor = designVariables.title;
1074-
}
1051+
final swatch = colorSwatchFor(context, store.subscriptions[streamId]);
1052+
final backgroundColor = swatch.barBackground;
1053+
final iconColor = swatch.iconOnBarBackground;
10751054

10761055
final Widget streamWidget;
10771056
if (!_containsDifferentChannels(narrow)) {

lib/widgets/theme.dart

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,10 +554,19 @@ class DesignVariables extends ThemeExtension<DesignVariables> {
554554
}
555555
}
556556

557+
// This is taken from:
558+
// https://github.com/zulip/zulip/blob/b248e2d93/web/src/stream_data.ts#L40
559+
const kDefaultChannelColorSwatchBaseColor = 0xffc2c2c2;
560+
557561
/// The theme-appropriate [ChannelColorSwatch] based on [subscription.color].
558562
///
563+
/// If [subscription] is null, [ChannelColorSwatch] will be based on
564+
/// [kDefaultChannelColorSwatchBaseColor].
565+
///
559566
/// For how this value is cached, see [ChannelColorSwatches.forBaseColor].
560-
ChannelColorSwatch colorSwatchFor(BuildContext context, Subscription subscription) {
567+
// TODO(#188) pick different colors for unsubscribed channels
568+
ChannelColorSwatch colorSwatchFor(BuildContext context, Subscription? subscription) {
561569
return DesignVariables.of(context)
562-
.channelColorSwatches.forBaseColor(subscription.color);
570+
.channelColorSwatches.forBaseColor(
571+
subscription?.color ?? kDefaultChannelColorSwatchBaseColor);
563572
}

test/widgets/theme_test.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,5 +178,13 @@ void main() {
178178
check(colorSwatchFor(element, subscription))
179179
.isSameColorSwatchAs(ChannelColorSwatch.dark(baseColor));
180180
});
181+
182+
testWidgets('fallback to default base color when no subscription', (tester) async {
183+
await tester.pumpWidget(const TestZulipApp());
184+
await tester.pump();
185+
final element = tester.element(find.byType(Placeholder));
186+
check(colorSwatchFor(element, null)).isSameColorSwatchAs(
187+
ChannelColorSwatch.light(kDefaultChannelColorSwatchBaseColor));
188+
});
181189
});
182190
}

0 commit comments

Comments
 (0)