Skip to content

Commit dd05f03

Browse files
Khader-1gnprice
authored andcommitted
channel_colors [nfc]: Rename StreamColorSwatches to ChannelColorSwatches
1 parent 8ae417f commit dd05f03

File tree

3 files changed

+33
-33
lines changed

3 files changed

+33
-33
lines changed

lib/widgets/channel_colors.dart

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import 'color.dart';
88

99
/// A lazily-computed map from a stream's base color to a
1010
/// corresponding [ChannelColorSwatch].
11-
abstract class StreamColorSwatches {
12-
/// The [StreamColorSwatches] for the light theme.
13-
static final StreamColorSwatches light = _StreamColorSwatchesLight();
11+
abstract class ChannelColorSwatches {
12+
/// The [ChannelColorSwatches] for the light theme.
13+
static final ChannelColorSwatches light = _ChannelColorSwatchesLight();
1414

15-
/// The [StreamColorSwatches] for the dark theme.
16-
static final StreamColorSwatches dark = _StreamColorSwatchesDark();
15+
/// The [ChannelColorSwatches] for the dark theme.
16+
static final ChannelColorSwatches dark = _ChannelColorSwatchesDark();
1717

1818
final Map<int, ChannelColorSwatch> _cache = {};
1919

@@ -23,7 +23,7 @@ abstract class StreamColorSwatches {
2323

2424
ChannelColorSwatch _computeForBaseColor(int base);
2525

26-
/// Gives a [StreamColorSwatches], lerped between [a] and [b] at [t].
26+
/// Gives a [ChannelColorSwatches], lerped between [a] and [b] at [t].
2727
///
2828
/// If [a] and [b] are [identical], returns [this].
2929
///
@@ -33,37 +33,37 @@ abstract class StreamColorSwatches {
3333
/// This computation is cached on the instance
3434
/// in order to save work building [t]'s animation frame when there are
3535
/// multiple UI elements using the same [subscription.color].
36-
static StreamColorSwatches lerp(StreamColorSwatches a, StreamColorSwatches b, double t) {
36+
static ChannelColorSwatches lerp(ChannelColorSwatches a, ChannelColorSwatches b, double t) {
3737
// This short-circuit helps when [a] and [b]
38-
// are both [StreamColorSwatches.light]
39-
// or both [StreamColorSwatches.dark].
38+
// are both [ChannelColorSwatches.light]
39+
// or both [ChannelColorSwatches.dark].
4040
// Empirically, [lerp] is called even when the theme hasn't changed,
4141
// so this is an important optimization.
4242
if (identical(a, b)) return a;
4343

44-
return _StreamColorSwatchesLerped(a, b, t);
44+
return _ChannelColorSwatchesLerped(a, b, t);
4545
}
4646
}
4747

48-
class _StreamColorSwatchesLight extends StreamColorSwatches {
49-
_StreamColorSwatchesLight();
48+
class _ChannelColorSwatchesLight extends ChannelColorSwatches {
49+
_ChannelColorSwatchesLight();
5050

5151
@override
5252
ChannelColorSwatch _computeForBaseColor(int base) => ChannelColorSwatch.light(base);
5353
}
5454

55-
class _StreamColorSwatchesDark extends StreamColorSwatches {
56-
_StreamColorSwatchesDark();
55+
class _ChannelColorSwatchesDark extends ChannelColorSwatches {
56+
_ChannelColorSwatchesDark();
5757

5858
@override
5959
ChannelColorSwatch _computeForBaseColor(int base) => ChannelColorSwatch.dark(base);
6060
}
6161

62-
class _StreamColorSwatchesLerped extends StreamColorSwatches {
63-
_StreamColorSwatchesLerped(this.a, this.b, this.t);
62+
class _ChannelColorSwatchesLerped extends ChannelColorSwatches {
63+
_ChannelColorSwatchesLerped(this.a, this.b, this.t);
6464

65-
final StreamColorSwatches a;
66-
final StreamColorSwatches b;
65+
final ChannelColorSwatches a;
66+
final ChannelColorSwatches b;
6767
final double t;
6868

6969
@override

lib/widgets/theme.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class DesignVariables extends ThemeExtension<DesignVariables> {
134134
icon: const Color(0xff666699),
135135
mainBackground: const Color(0xfff0f0f0),
136136
title: const Color(0xff1a1a1a),
137-
streamColorSwatches: StreamColorSwatches.light,
137+
streamColorSwatches: ChannelColorSwatches.light,
138138
star: const HSLColor.fromAHSL(0.5, 47, 1, 0.41).toColor(),
139139
);
140140

@@ -145,7 +145,7 @@ class DesignVariables extends ThemeExtension<DesignVariables> {
145145
icon: const Color(0xff7070c2),
146146
mainBackground: const Color(0xff1d1d1d),
147147
title: const Color(0xffffffff),
148-
streamColorSwatches: StreamColorSwatches.dark,
148+
streamColorSwatches: ChannelColorSwatches.dark,
149149
// TODO(#95) unchanged in dark theme?
150150
star: const HSLColor.fromAHSL(0.5, 47, 1, 0.41).toColor(),
151151
);
@@ -177,7 +177,7 @@ class DesignVariables extends ThemeExtension<DesignVariables> {
177177
final Color title;
178178

179179
// Not exactly from the Figma design, but from Vlad anyway.
180-
final StreamColorSwatches streamColorSwatches;
180+
final ChannelColorSwatches streamColorSwatches;
181181

182182
// Not named variables in Figma; taken from older Figma drafts, or elsewhere.
183183
final Color star;
@@ -189,7 +189,7 @@ class DesignVariables extends ThemeExtension<DesignVariables> {
189189
Color? icon,
190190
Color? mainBackground,
191191
Color? title,
192-
StreamColorSwatches? streamColorSwatches,
192+
ChannelColorSwatches? streamColorSwatches,
193193
Color? star,
194194
}) {
195195
return DesignVariables._(
@@ -214,15 +214,15 @@ class DesignVariables extends ThemeExtension<DesignVariables> {
214214
icon: Color.lerp(icon, other.icon, t)!,
215215
mainBackground: Color.lerp(mainBackground, other.mainBackground, t)!,
216216
title: Color.lerp(title, other.title, t)!,
217-
streamColorSwatches: StreamColorSwatches.lerp(streamColorSwatches, other.streamColorSwatches, t),
217+
streamColorSwatches: ChannelColorSwatches.lerp(streamColorSwatches, other.streamColorSwatches, t),
218218
star: Color.lerp(star, other.star, t)!,
219219
);
220220
}
221221
}
222222

223223
/// The theme-appropriate [ChannelColorSwatch] based on [subscription.color].
224224
///
225-
/// For how this value is cached, see [StreamColorSwatches.forBaseColor].
225+
/// For how this value is cached, see [ChannelColorSwatches.forBaseColor].
226226
ChannelColorSwatch colorSwatchFor(BuildContext context, Subscription subscription) {
227227
return DesignVariables.of(context)
228228
.streamColorSwatches.forBaseColor(subscription.color);

test/widgets/channel_colors_test.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import 'package:zulip/widgets/channel_colors.dart';
66
import 'channel_colors_checks.dart';
77

88
void main() {
9-
group('StreamColorSwatches', () {
9+
group('ChannelColorSwatches', () {
1010
test('.light', () {
11-
final instance = StreamColorSwatches.light;
11+
final instance = ChannelColorSwatches.light;
1212

1313
const base1 = 0xff76ce90;
1414
final swatch1 = instance.forBaseColor(base1);
@@ -24,7 +24,7 @@ void main() {
2424

2525
// TODO deduplicate with corresponding light-theme test?
2626
test('.dark', () {
27-
final instance = StreamColorSwatches.dark;
27+
final instance = ChannelColorSwatches.dark;
2828

2929
const base1 = 0xff76ce90;
3030
final swatch1 = instance.forBaseColor(base1);
@@ -40,16 +40,16 @@ void main() {
4040

4141
group('lerp', () {
4242
test('on identical instances', () {
43-
final light = StreamColorSwatches.light;
44-
check(StreamColorSwatches.lerp(light, light, 0.5)).identicalTo(light);
43+
final light = ChannelColorSwatches.light;
44+
check(ChannelColorSwatches.lerp(light, light, 0.5)).identicalTo(light);
4545

46-
final dark = StreamColorSwatches.dark;
47-
check(StreamColorSwatches.lerp(dark, dark, 0.5)).identicalTo(dark);
46+
final dark = ChannelColorSwatches.dark;
47+
check(ChannelColorSwatches.lerp(dark, dark, 0.5)).identicalTo(dark);
4848
});
4949

5050
test('from light to dark', () {
51-
final instance = StreamColorSwatches
52-
.lerp(StreamColorSwatches.light, StreamColorSwatches.dark, 0.4);
51+
final instance = ChannelColorSwatches
52+
.lerp(ChannelColorSwatches.light, ChannelColorSwatches.dark, 0.4);
5353

5454
const base1 = 0xff76ce90;
5555
final swatch1 = instance.forBaseColor(base1);

0 commit comments

Comments
 (0)