mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-09-29 21:02:09 +02:00
fix(mornye): preserve contrast with custom accent colors
This commit is contained in:
@@ -66,7 +66,9 @@ class MornyeTheme extends ThemeExtension<MornyeTheme> {
|
||||
MornyeAccent.purple => CupertinoColors.systemPurple,
|
||||
MornyeAccent.pink => CupertinoColors.systemPink,
|
||||
};
|
||||
return dark ? color.darkColor : color.color;
|
||||
// Accents also label links and small controls on white surfaces.
|
||||
if (!dark && accent == MornyeAccent.green) return const Color(0xff24863d);
|
||||
return dark ? color.darkColor : color.highContrastColor;
|
||||
}
|
||||
|
||||
static final tokens = AppTokens.standard.copyWith(
|
||||
@@ -169,7 +171,11 @@ class MornyeTheme extends ThemeExtension<MornyeTheme> {
|
||||
brightness: brightness,
|
||||
).copyWith(
|
||||
primary: accent,
|
||||
onPrimary: Colors.white,
|
||||
onPrimary:
|
||||
selectedAccent == MornyeAccent.red ||
|
||||
accent.computeLuminance() < 0.179
|
||||
? Colors.white
|
||||
: Colors.black,
|
||||
primaryContainer: grouped,
|
||||
onPrimaryContainer: accent,
|
||||
secondary: accent,
|
||||
|
||||
@@ -10,6 +10,35 @@ import 'package:spotiflac_android/theme/dynamic_color_wrapper.dart';
|
||||
import 'package:spotiflac_android/theme/mornye_theme.dart';
|
||||
|
||||
void main() {
|
||||
test('custom accents keep text readable in both appearances', () {
|
||||
double contrast(Color first, Color second) {
|
||||
final a = first.computeLuminance();
|
||||
final b = second.computeLuminance();
|
||||
return a > b ? (a + 0.05) / (b + 0.05) : (b + 0.05) / (a + 0.05);
|
||||
}
|
||||
|
||||
for (final brightness in Brightness.values) {
|
||||
for (final accent in MornyeAccent.values.where(
|
||||
(accent) => accent != MornyeAccent.red,
|
||||
)) {
|
||||
final scheme = MornyeTheme.build(
|
||||
brightness,
|
||||
accent: accent,
|
||||
).colorScheme;
|
||||
expect(
|
||||
contrast(scheme.primary, scheme.surface),
|
||||
greaterThanOrEqualTo(4.5),
|
||||
reason: '$accent on $brightness',
|
||||
);
|
||||
expect(
|
||||
contrast(scheme.onPrimary, scheme.primary),
|
||||
greaterThanOrEqualTo(4.5),
|
||||
reason: 'Button text for $accent on $brightness',
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Future<void> openSettings(
|
||||
WidgetTester tester,
|
||||
SharedPreferences prefs,
|
||||
|
||||
Reference in New Issue
Block a user