Skip to content

Commit 3ebe6fb

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 generate different colors within constraints for the unsubscribed channels (since only subscribed channels have color data from the server), 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 channels are needed, namely the topic list.
1 parent 37dc9ea commit 3ebe6fb

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
@@ -45,9 +45,6 @@ class MessageListTheme extends ThemeExtension<MessageListTheme> {
4545
unreadMarker: const HSLColor.fromAHSL(1, 227, 0.78, 0.59).toColor(),
4646

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

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

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

7367
MessageListTheme._({
@@ -78,7 +72,6 @@ class MessageListTheme extends ThemeExtension<MessageListTheme> {
7872
required this.streamRecipientHeaderChevronRight,
7973
required this.unreadMarker,
8074
required this.unreadMarkerGap,
81-
required this.unsubscribedStreamRecipientHeaderBg,
8275
});
8376

8477
/// The [MessageListTheme] from the context's active theme.
@@ -98,7 +91,6 @@ class MessageListTheme extends ThemeExtension<MessageListTheme> {
9891
final Color streamRecipientHeaderChevronRight;
9992
final Color unreadMarker;
10093
final Color unreadMarkerGap;
101-
final Color unsubscribedStreamRecipientHeaderBg;
10294

10395
@override
10496
MessageListTheme copyWith({
@@ -109,7 +101,6 @@ class MessageListTheme extends ThemeExtension<MessageListTheme> {
109101
Color? streamRecipientHeaderChevronRight,
110102
Color? unreadMarker,
111103
Color? unreadMarkerGap,
112-
Color? unsubscribedStreamRecipientHeaderBg,
113104
}) {
114105
return MessageListTheme._(
115106
bgMessageRegular: bgMessageRegular ?? this.bgMessageRegular,
@@ -119,7 +110,6 @@ class MessageListTheme extends ThemeExtension<MessageListTheme> {
119110
streamRecipientHeaderChevronRight: streamRecipientHeaderChevronRight ?? this.streamRecipientHeaderChevronRight,
120111
unreadMarker: unreadMarker ?? this.unreadMarker,
121112
unreadMarkerGap: unreadMarkerGap ?? this.unreadMarkerGap,
122-
unsubscribedStreamRecipientHeaderBg: unsubscribedStreamRecipientHeaderBg ?? this.unsubscribedStreamRecipientHeaderBg,
123113
);
124114
}
125115

@@ -136,7 +126,6 @@ class MessageListTheme extends ThemeExtension<MessageListTheme> {
136126
streamRecipientHeaderChevronRight: Color.lerp(streamRecipientHeaderChevronRight, other.streamRecipientHeaderChevronRight, t)!,
137127
unreadMarker: Color.lerp(unreadMarker, other.unreadMarker, t)!,
138128
unreadMarkerGap: Color.lerp(unreadMarkerGap, other.unreadMarkerGap, t)!,
139-
unsubscribedStreamRecipientHeaderBg: Color.lerp(unsubscribedStreamRecipientHeaderBg, other.unsubscribedStreamRecipientHeaderBg, t)!,
140129
);
141130
}
142131
}
@@ -227,9 +216,8 @@ class _MessageListPageState extends State<MessageListPage> implements MessageLis
227216
case ChannelNarrow(:final streamId):
228217
case TopicNarrow(:final streamId):
229218
final subscription = store.subscriptions[streamId];
230-
appBarBackgroundColor = subscription != null
231-
? colorSwatchFor(context, subscription).barBackground
232-
: messageListTheme.unsubscribedStreamRecipientHeaderBg;
219+
appBarBackgroundColor =
220+
colorSwatchFor(context, subscription).barBackground;
233221
// All recipient headers will match this color; remove distracting line
234222
// (but are recipient headers even needed for topic narrows?)
235223
removeAppBarBottomBorder = true;
@@ -1053,24 +1041,15 @@ class StreamMessageRecipientHeader extends StatelessWidget {
10531041
// https://github.com/zulip/zulip-mobile/issues/5511
10541042
final store = PerAccountStoreWidget.of(context);
10551043
final designVariables = DesignVariables.of(context);
1044+
final messageListTheme = MessageListTheme.of(context);
10561045
final zulipLocalizations = ZulipLocalizations.of(context);
10571046

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

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

10751054
final Widget streamWidget;
10761055
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)