Skip to content

Commit af2e178

Browse files
committed
theme: Implement DesignVariables.dark
1 parent 3ac8cec commit af2e178

File tree

2 files changed

+70
-12
lines changed

2 files changed

+70
-12
lines changed

lib/widgets/theme.dart

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ ThemeData zulipThemeData(BuildContext context) {
3636
: Brightness.light;
3737
switch (brightness) {
3838
case Brightness.light: {
39-
designVariables = DesignVariables();
39+
designVariables = DesignVariables.light();
4040
themeExtensions = [ContentTheme.light(context), designVariables];
4141
}
4242
case Brightness.dark: {
43-
designVariables = DesignVariables(); // TODO(#95)
43+
designVariables = DesignVariables.dark();
4444
themeExtensions = [ContentTheme.dark(context), designVariables];
4545
}
4646
}
@@ -115,13 +115,25 @@ const kZulipBrandColor = Color.fromRGBO(0x64, 0x92, 0xfe, 1);
115115
/// For how to export these from the Figma, see:
116116
/// https://www.figma.com/design/1JTNtYo9memgW7vV6d0ygq/Zulip-Mobile?node-id=2945-49492&t=MEb4vtp7S26nntxm-0
117117
class DesignVariables extends ThemeExtension<DesignVariables> {
118-
DesignVariables() :
119-
bgTopBar = const Color(0xfff5f5f5),
120-
borderBar = const Color(0x33000000),
121-
icon = const Color(0xff666699),
122-
mainBackground = const Color(0xfff0f0f0),
123-
title = const Color(0xff1a1a1a),
124-
streamColorSwatches = StreamColorSwatches.light;
118+
DesignVariables.light() :
119+
this._(
120+
bgTopBar: const Color(0xfff5f5f5),
121+
borderBar: const Color(0x33000000),
122+
icon: const Color(0xff666699),
123+
mainBackground: const Color(0xfff0f0f0),
124+
title: const Color(0xff1a1a1a),
125+
streamColorSwatches: StreamColorSwatches.light,
126+
);
127+
128+
DesignVariables.dark() :
129+
this._(
130+
bgTopBar: const Color(0xff242424),
131+
borderBar: Colors.black.withOpacity(0.41),
132+
icon: const Color(0xff7070c2),
133+
mainBackground: const Color(0xff1d1d1d),
134+
title: const Color(0xffffffff),
135+
streamColorSwatches: StreamColorSwatches.dark,
136+
);
125137

126138
DesignVariables._({
127139
required this.bgTopBar,

test/widgets/theme_test.dart

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,48 @@ void main() {
7676
button: TextButton(onPressed: () {}, child: const Text(buttonText)));
7777
});
7878

79+
group('DesignVariables', () {
80+
group('lerp', () {
81+
testWidgets('light -> light', (tester) async {
82+
final a = DesignVariables.light();
83+
final b = DesignVariables.light();
84+
check(() => a.lerp(b, 0.5)).returnsNormally();
85+
});
86+
87+
testWidgets('light -> dark', (tester) async {
88+
final a = DesignVariables.light();
89+
final b = DesignVariables.dark();
90+
check(() => a.lerp(b, 0.5)).returnsNormally();
91+
});
92+
93+
testWidgets('dark -> light', (tester) async {
94+
final a = DesignVariables.dark();
95+
final b = DesignVariables.light();
96+
check(() => a.lerp(b, 0.5)).returnsNormally();
97+
});
98+
99+
testWidgets('dark -> dark', (tester) async {
100+
final a = DesignVariables.dark();
101+
final b = DesignVariables.dark();
102+
check(() => a.lerp(b, 0.5)).returnsNormally();
103+
});
104+
});
105+
});
106+
79107
group('colorSwatchFor', () {
80108
const baseColor = 0xff76ce90;
81109

82-
testWidgets('light $baseColor', (WidgetTester tester) async {
110+
testWidgets('light–dark animation', (WidgetTester tester) async {
83111
addTearDown(testBinding.reset);
84112

85113
final subscription = eg.subscription(eg.stream(), color: baseColor);
86114

115+
assert(!debugFollowPlatformBrightness); // to be removed with #95
116+
debugFollowPlatformBrightness = true;
117+
addTearDown(() { debugFollowPlatformBrightness = false; });
118+
tester.platformDispatcher.platformBrightnessTestValue = Brightness.light;
119+
addTearDown(tester.platformDispatcher.clearPlatformBrightnessTestValue);
120+
87121
await tester.pumpWidget(const ZulipApp());
88122
await tester.pump();
89123

@@ -96,8 +130,20 @@ void main() {
96130
// Compares all the swatch's members; see [ColorSwatch]'s `operator ==`.
97131
check(colorSwatchFor(element, subscription))
98132
.equals(StreamColorSwatch.light(baseColor));
99-
});
100133

101-
// TODO(#95) test with Brightness.dark and lerping between light/dark
134+
tester.platformDispatcher.platformBrightnessTestValue = Brightness.dark;
135+
await tester.pump();
136+
137+
await tester.pump(kThemeAnimationDuration * 0.4);
138+
check(colorSwatchFor(element, subscription))
139+
.equals(StreamColorSwatch.lerp(
140+
StreamColorSwatch.light(baseColor),
141+
StreamColorSwatch.dark(baseColor),
142+
0.4)!);
143+
144+
await tester.pump(kThemeAnimationDuration * 0.6);
145+
check(colorSwatchFor(element, subscription))
146+
.equals(StreamColorSwatch.dark(baseColor));
147+
});
102148
});
103149
}

0 commit comments

Comments
 (0)