|
1 | 1 | import 'package:flutter/foundation.dart';
|
2 |
| -import 'package:flutter/painting.dart'; |
3 |
| -import 'package:flutter_color_models/flutter_color_models.dart'; |
4 | 2 | import 'package:json_annotation/json_annotation.dart';
|
5 | 3 |
|
6 |
| -import '../../widgets/color.dart'; |
| 4 | +import '../../widgets/stream_colors.dart'; |
7 | 5 | import 'events.dart';
|
8 | 6 | import 'initial_snapshot.dart';
|
9 | 7 | import 'reaction.dart';
|
@@ -459,156 +457,6 @@ class Subscription extends ZulipStream {
|
459 | 457 | Map<String, dynamic> toJson() => _$SubscriptionToJson(this);
|
460 | 458 | }
|
461 | 459 |
|
462 |
| -/// A [ColorSwatch] with colors related to a base stream color. |
463 |
| -/// |
464 |
| -/// Use this in UI code for colors related to [Subscription.color], |
465 |
| -/// such as the background of an unread count badge. |
466 |
| -class StreamColorSwatch extends ColorSwatch<StreamColorVariant> { |
467 |
| - StreamColorSwatch.light(int base) : this._(base, _computeLight(base)); |
468 |
| - StreamColorSwatch.dark(int base) : this._(base, _computeDark(base)); |
469 |
| - |
470 |
| - const StreamColorSwatch._(int base, this._swatch) : super(base, _swatch); |
471 |
| - |
472 |
| - final Map<StreamColorVariant, Color> _swatch; |
473 |
| - |
474 |
| - /// The [Subscription.color] int that the swatch is based on. |
475 |
| - Color get base => this[StreamColorVariant.base]!; |
476 |
| - |
477 |
| - Color get unreadCountBadgeBackground => this[StreamColorVariant.unreadCountBadgeBackground]!; |
478 |
| - |
479 |
| - /// The stream icon on a plain-colored surface, such as white. |
480 |
| - /// |
481 |
| - /// For the icon on a [barBackground]-colored surface, |
482 |
| - /// use [iconOnBarBackground] instead. |
483 |
| - Color get iconOnPlainBackground => this[StreamColorVariant.iconOnPlainBackground]!; |
484 |
| - |
485 |
| - /// The stream icon on a [barBackground]-colored surface. |
486 |
| - /// |
487 |
| - /// For the icon on a plain surface, use [iconOnPlainBackground] instead. |
488 |
| - /// This color is chosen to enhance contrast with [barBackground]: |
489 |
| - /// <https://github.com/zulip/zulip/pull/27485> |
490 |
| - Color get iconOnBarBackground => this[StreamColorVariant.iconOnBarBackground]!; |
491 |
| - |
492 |
| - /// The background color of a bar representing a stream, like a recipient bar. |
493 |
| - /// |
494 |
| - /// Use this in the message list, the "Inbox" view, and the "Streams" view. |
495 |
| - Color get barBackground => this[StreamColorVariant.barBackground]!; |
496 |
| - |
497 |
| - static Map<StreamColorVariant, Color> _computeLight(int base) { |
498 |
| - final baseAsColor = Color(base); |
499 |
| - |
500 |
| - final clamped20to75 = clampLchLightness(baseAsColor, 20, 75); |
501 |
| - final clamped20to75AsHsl = HSLColor.fromColor(clamped20to75); |
502 |
| - |
503 |
| - return { |
504 |
| - StreamColorVariant.base: baseAsColor, |
505 |
| - |
506 |
| - // Follows `.unread-count` in Vlad's replit: |
507 |
| - // <https://replit.com/@VladKorobov/zulip-sidebar#script.js> |
508 |
| - // <https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/design.3A.20.23F117.20.22Inbox.22.20screen/near/1624484> |
509 |
| - // |
510 |
| - // TODO fix bug where our results differ from the replit's (see unit tests) |
511 |
| - StreamColorVariant.unreadCountBadgeBackground: |
512 |
| - clampLchLightness(baseAsColor, 30, 70) |
513 |
| - .withOpacity(0.3), |
514 |
| - |
515 |
| - // Follows `.sidebar-row__icon` in Vlad's replit: |
516 |
| - // <https://replit.com/@VladKorobov/zulip-sidebar#script.js> |
517 |
| - // |
518 |
| - // TODO fix bug where our results differ from the replit's (see unit tests) |
519 |
| - StreamColorVariant.iconOnPlainBackground: clamped20to75, |
520 |
| - |
521 |
| - // Follows `.recepeient__icon` in Vlad's replit: |
522 |
| - // <https://replit.com/@VladKorobov/zulip-topic-feed-colors#script.js> |
523 |
| - // <https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/design.3A.20.23F117.20.22Inbox.22.20screen/near/1624484> |
524 |
| - // |
525 |
| - // TODO fix bug where our results differ from the replit's (see unit tests) |
526 |
| - StreamColorVariant.iconOnBarBackground: |
527 |
| - clamped20to75AsHsl |
528 |
| - .withLightness(clampDouble(clamped20to75AsHsl.lightness - 0.12, 0.0, 1.0)) |
529 |
| - .toColor(), |
530 |
| - |
531 |
| - // Follows `.recepient` in Vlad's replit: |
532 |
| - // <https://replit.com/@VladKorobov/zulip-topic-feed-colors#script.js> |
533 |
| - // |
534 |
| - // TODO I think [LabColor.interpolate] doesn't actually do LAB mixing; |
535 |
| - // it just calls up to the superclass method [ColorModel.interpolate]: |
536 |
| - // <https://pub.dev/documentation/flutter_color_models/latest/flutter_color_models/ColorModel/interpolate.html> |
537 |
| - // which does ordinary RGB mixing. Investigate and send a PR? |
538 |
| - // TODO fix bug where our results differ from the replit's (see unit tests) |
539 |
| - StreamColorVariant.barBackground: |
540 |
| - LabColor.fromColor(const Color(0xfff9f9f9)) |
541 |
| - .interpolate(LabColor.fromColor(clamped20to75), 0.22) |
542 |
| - .toColor(), |
543 |
| - }; |
544 |
| - } |
545 |
| - |
546 |
| - static Map<StreamColorVariant, Color> _computeDark(int base) { |
547 |
| - final baseAsColor = Color(base); |
548 |
| - |
549 |
| - final clamped20to75 = clampLchLightness(baseAsColor, 20, 75); |
550 |
| - |
551 |
| - return { |
552 |
| - // See comments in [_computeLight] about what these computations are based |
553 |
| - // on, and how the resulting values are a little off sometimes. The |
554 |
| - // comments mostly apply here too. |
555 |
| - |
556 |
| - StreamColorVariant.base: baseAsColor, |
557 |
| - StreamColorVariant.unreadCountBadgeBackground: |
558 |
| - clampLchLightness(baseAsColor, 30, 70) |
559 |
| - .withOpacity(0.3), |
560 |
| - StreamColorVariant.iconOnPlainBackground: clamped20to75, |
561 |
| - |
562 |
| - // Follows the web app (as of zulip/zulip@db03369ac); see |
563 |
| - // get_stream_privacy_icon_color in web/src/stream_color.ts. |
564 |
| - // |
565 |
| - // `.recepeient__icon` in Vlad's replit gives something different so we |
566 |
| - // don't use that: |
567 |
| - // <https://replit.com/@VladKorobov/zulip-topic-feed-colors#script.js> |
568 |
| - // <https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/design.3A.20.23F117.20.22Inbox.22.20screen/near/1624484> |
569 |
| - // But that's OK because Vlad said "I feel like current dark theme contrast |
570 |
| - // is fine", and when he said that, this had been the web app's icon color |
571 |
| - // for 6+ months (since zulip/zulip@023584e04): |
572 |
| - // https://chat.zulip.org/#narrow/stream/101-design/topic/UI.20redesign.3A.20recipient.20bar.20colors/near/1675786 |
573 |
| - // |
574 |
| - // TODO fix bug where our results are unexpected (see unit tests) |
575 |
| - StreamColorVariant.iconOnBarBackground: clamped20to75, |
576 |
| - |
577 |
| - StreamColorVariant.barBackground: |
578 |
| - LabColor.fromColor(const Color(0xff000000)) |
579 |
| - .interpolate(LabColor.fromColor(clamped20to75), 0.38) |
580 |
| - .toColor(), |
581 |
| - }; |
582 |
| - } |
583 |
| - |
584 |
| - /// Copied from [ColorSwatch.lerp]. |
585 |
| - static StreamColorSwatch? lerp(StreamColorSwatch? a, StreamColorSwatch? b, double t) { |
586 |
| - if (identical(a, b)) { |
587 |
| - return a; |
588 |
| - } |
589 |
| - final Map<StreamColorVariant, Color> swatch; |
590 |
| - if (b == null) { |
591 |
| - swatch = a!._swatch.map((key, color) => MapEntry(key, Color.lerp(color, null, t)!)); |
592 |
| - } else { |
593 |
| - if (a == null) { |
594 |
| - swatch = b._swatch.map((key, color) => MapEntry(key, Color.lerp(null, color, t)!)); |
595 |
| - } else { |
596 |
| - swatch = a._swatch.map((key, color) => MapEntry(key, Color.lerp(color, b[key], t)!)); |
597 |
| - } |
598 |
| - } |
599 |
| - return StreamColorSwatch._(Color.lerp(a, b, t)!.value, swatch); |
600 |
| - } |
601 |
| -} |
602 |
| - |
603 |
| -@visibleForTesting |
604 |
| -enum StreamColorVariant { |
605 |
| - base, |
606 |
| - unreadCountBadgeBackground, |
607 |
| - iconOnPlainBackground, |
608 |
| - iconOnBarBackground, |
609 |
| - barBackground, |
610 |
| -} |
611 |
| - |
612 | 460 | @JsonEnum(fieldRename: FieldRename.snake, valueField: "apiValue")
|
613 | 461 | enum UserTopicVisibilityPolicy {
|
614 | 462 | none(apiValue: 0),
|
|
0 commit comments