Skip to content

Commit 0c44b5f

Browse files
committed
model: Add StreamColorSwatch.recipientBar{Icon,Background}
1 parent c0311de commit 0c44b5f

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

lib/api/model/model.dart

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:flutter/foundation.dart';
22
import 'package:flutter/painting.dart';
3+
import 'package:flutter_color_models/flutter_color_models.dart';
34
import 'package:json_annotation/json_annotation.dart';
45

56
import '../../widgets/color.dart';
@@ -384,9 +385,15 @@ class StreamColorSwatch extends ColorSwatch<_StreamColorVariant> {
384385

385386
Color get unreadCountBadgeBackground => this[_StreamColorVariant.unreadCountBadgeBackground]!;
386387

388+
Color get recipientBarIcon => this[_StreamColorVariant.recipientBarIcon]!;
389+
390+
Color get recipientBarBackground => this[_StreamColorVariant.recipientBarBackground]!;
391+
387392
static Map<_StreamColorVariant, Color> _compute(int base) {
388393
final baseAsColor = Color(base);
389394

395+
final clamped20to75 = clampLchLightness(baseAsColor, 20, 75);
396+
390397
return {
391398
_StreamColorVariant.base: baseAsColor,
392399

@@ -398,13 +405,34 @@ class StreamColorSwatch extends ColorSwatch<_StreamColorVariant> {
398405
// TODO profiling for expensive computation
399406
_StreamColorVariant.unreadCountBadgeBackground:
400407
clampLchLightness(baseAsColor, 30, 70).withOpacity(0.3),
408+
409+
// Follows `.recepeient__icon` in Vlad's replit, except (to match web)
410+
// with a `.darken(0.12)` omitted:
411+
// <https://replit.com/@VladKorobov/zulip-topic-feed-colors#script.js>
412+
// <https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/design.3A.20.23F117.20.22Inbox.22.20screen/near/1624484>
413+
//
414+
// TODO await decision on that `.darken(0.12)` or another way to raise contrast:
415+
// https://chat.zulip.org/#narrow/stream/101-design/topic/UI.20redesign.3A.20recipient.20bar.20colors/near/1675786
416+
_StreamColorVariant.recipientBarIcon: clamped20to75,
417+
418+
// Follows `.recepient` in Vlad's replit:
419+
// <https://replit.com/@VladKorobov/zulip-topic-feed-colors#script.js>
420+
//
421+
// TODO I think [LabColor.interpolate] doesn't actually do LAB mixing;
422+
// it just calls up to the superclass method [ColorModel.interpolate]:
423+
// <https://pub.dev/documentation/flutter_color_models/latest/flutter_color_models/ColorModel/interpolate.html>
424+
// which does ordinary RGB mixing. Investigate and send a PR?
425+
_StreamColorVariant.recipientBarBackground: LabColor.fromColor(const Color(0xfff9f9f9))
426+
.interpolate(LabColor.fromColor(clamped20to75), 0.22),
401427
};
402428
}
403429
}
404430

405431
enum _StreamColorVariant {
406432
base,
407433
unreadCountBadgeBackground,
434+
recipientBarIcon,
435+
recipientBarBackground,
408436
}
409437

410438
/// As in the get-messages response.

test/api/model/model_checks.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import 'package:zulip/api/model/model.dart';
66
extension StreamColorSwatchChecks on Subject<StreamColorSwatch> {
77
Subject<Color> get base => has((s) => s.base, 'base');
88
Subject<Color> get unreadCountBadgeBackground => has((s) => s.unreadCountBadgeBackground, 'unreadCountBadgeBackground');
9+
Subject<Color> get recipientBarIcon => has((s) => s.recipientBarIcon, 'recipientBarIcon');
10+
Subject<Color> get recipientBarBackground => has((s) => s.recipientBarBackground, 'recipientBarBackground');
911
}
1012

1113
extension MessageChecks on Subject<Message> {

test/api/model/model_test.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ void main() {
152152
runCheck(0xFFFFFFE0, const Color(0x4dadad90)); // 0x4dacad90
153153
runCheck(0xFFFF69B4, const Color(0x4dff69b4));
154154
});
155+
156+
// TODO recipientBarIcon, recipientBarBackground
155157
});
156158
});
157159

0 commit comments

Comments
 (0)