Skip to content

theme: Add ThemeExtension for Figma design variables; add/use two more variables in AppBar #734

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 17, 2024

Conversation

chrisbobbe
Copy link
Collaborator

It seems helpful to have a central place to put the design variables we export from the Figma design, to help pave the way to implementing it. This PR adds such a place, as a ThemeExtension.

It also takes two more color variables from the Figma (title and icon), to add to the three we've already been using, and applies them to the app bar, since that's something we see marked "ready for dev": https://www.figma.com/design/1JTNtYo9memgW7vV6d0ygq/Zulip-Mobile?node-id=2957-50895&m=dev

While we're at it, this also applies the Figma's specified font weight, size, and line height to the app-bar title. (Those aren't expressed as variables in the Figma.)

There's still more to do to align the app bar with what we see in the Figma, and I add TODOs about some of this.

Before After
B688D1CA-8C88-44E2-AC57-35EF75F32F47 519ECC53-DCB1-453D-A141-D1F5F8E7BCC2

@chrisbobbe chrisbobbe added the integration review Added by maintainers when PR may be ready for integration label Jun 14, 2024
@chrisbobbe chrisbobbe requested a review from gnprice June 14, 2024 04:18
@chrisbobbe
Copy link
Collaborator Author

chrisbobbe commented Jun 14, 2024

In this commit:

ui: Follow new Figma in app-bar title style

the titleSpacing: 4 affects the app-bar layout in the lightbox: a gap of 16 to the left of the title is replaced by a gap of 4.

I think the change is probably OK, and possibly an improvement (in fact that particular app bar might do better with titleSpacing: 0)? Here are the screenshots:

Before After
89D837A8-08F3-4852-8298-0442E2F516EE BC86B64F-BA40-44E0-BC87-B4B74864B1AA

@chrisbobbe
Copy link
Collaborator Author

chrisbobbe commented Jun 14, 2024

Ah hmm, I wonder if it's worth polishing the message list app bar, which I realized is also affected by these changes. I think it looks a bit worse now, but I don't think there's a ready Figma design for it yet.

—ah, looks like basically a worsening of something already flagged in the code:

      // TODO(design): The vertical alignment of the stream privacy icon is a bit ad hoc.
      //   For screenshots of some experiments, see:
      //     https://github.com/zulip/zulip-flutter/pull/219#discussion_r1281024746
Before After
723EFA50-B392-43EF-AEBB-C813A9D3370F 4E4DE33F-A843-4568-AB19-A5353DCBCD95

@chrisbobbe
Copy link
Collaborator Author

chrisbobbe commented Jun 14, 2024

Ah hmm, I wonder if it's worth polishing the message list app bar

I've added a commit that does this:

msglist: Tweak app-bar title to look better after recent text-size change

It does change the vertical alignment from baseline to center. One concern that came up in the discussion linked from the code comment (#219 (comment) ) was that choosing "center" would make the icon look too low. But I don't think it looks too low now (see screenshots below); maybe one factor is our change of font since that older discussion?

Screenshots shown after the new commit, with different values of the system text-size setting:

Text scaling <1x Text scaling 1x Text scaling >1x
B9676499-0FD9-46E1-BBA6-65D1C27021CD CCD4E617-4B08-4EAA-9665-E582CEF1034D 3CA95394-D384-4E37-8C0B-87BAF053823E
C0A0BBE3-00AB-4C5C-9A3B-10BE9A0293F0 1F80E38D-7906-438B-936A-4D630F2E5C32 4D6F6525-64A1-4138-8FB0-50D2E7CBBC30
7BA7A7F4-E445-4AD9-B70E-9A8C085412AB 95D12F41-5473-4348-B63A-503C4D7D0989 0E9F0FE7-3882-4474-A8A7-A0984E86BBFE

@alya
Copy link
Collaborator

alya commented Jun 14, 2024

I guess the icon starts looking too small in the screenshots on the right; I don't know how fixable that is.

@chrisbobbe
Copy link
Collaborator Author

chrisbobbe commented Jun 14, 2024

I guess the icon starts looking too small in the screenshots on the right; I don't know how fixable that is.

Hmm, yeah; the icon is closely associated with the text, so probably it should scale with it, instead of always being the same size? There's a setting for that; it should be easy: https://api.flutter.dev/flutter/widgets/Icon/applyTextScaling.html

This could be done separately as a followup, I think. The icon in main doesn't scale either.

Copy link
Member

@gnprice gnprice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @chrisbobbe! This all LGTM; one nit below, and please go ahead and merge.

I think the behavior shown in the screenshots where the icon doesn't grow when the text is big is actually fine — it's normal and helpful that increasing text size doesn't cause the rest of the UI to expand, other than text. See discussion here:
https://github.com/zulip/zulip-mobile/blob/e352f563ecf2fa9b09b688d5a65b6bc89b0358bc/docs/background/webview.md#why-mostly-px-and-not-rem

Arguably these particular icons are more text-like (like a kind of emoji) and so should scale with the text size after all. But I don't think we need to worry about it.

Comment on lines 25 to 27
titleTextStyle: TextStyle(
inherit: false,

color: designVariables.title,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
titleTextStyle: TextStyle(
inherit: false,
color: designVariables.title,
titleTextStyle: TextStyle(
inherit: false,
color: designVariables.title,

/// For how to export these from the Figma, see:
/// https://www.figma.com/design/1JTNtYo9memgW7vV6d0ygq/Zulip-Mobile?node-id=2945-49492&t=MEb4vtp7S26nntxm-0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handy link!

This seems like a handy function to have around; there were a
handful of places that were wanting something like this.

In b75908b, we aimed to make ContentTheme.textStylePlainParagraph
a very direct, NFC translation of some Typography defaults, but we
accidentally fell short a little bit: I had forgotten that we
support Japanese, and that commit just hardcoded
TextBaseline.alphabetic, which was a regression. Since the "geometry
TextThemes" for M3 only differ in `textBaseline` [1], I believe that
commit would have been a pure translation if we had used this new
function. (We did follow up with 6284ed5, removing the
textBaseline field altogether. But that put the style at odds with
text basically everywhere else, which inherits a textBaseline from
Typography.)

I was hoping to see an improvement in how Japanese text is rendered
after this change, but I wasn't able to; I didn't notice any change
in appearance between TextBaseline.alphabetic and
TextBaseline.ideographic (or a TextStyle that omits the field, in
the case of ContentTheme.textStylePlainParagraph.) Anyway, if this
is because of incomplete support for `ideographic`, at least we'll
be well-prepared to take improvements as they arrive.

Someone did post some screenshots with both values rendering
identically:
  flutter/flutter#94680

[1] The Material 2 spec apparently called for more differences that
    were removed in Material 3; see the docs for
    Typography.dense2021 and tall2021.
Much like we did in b75908b for
ContentTheme.textStylePlainParagraph, this is meant to collect all
the details that had been implicitly defining the app-bar title
style, from various sources:
- [_M3Typography.englishLike] or [_M3Typography.dense] (the latter
  for Japanese)
- [Typography.blackCupertino] or [Typography.blackMountainView]
  (depending on platform)
- `zulipTypography` in lib/widgets/text.dart
- [ColorScheme.onSurface]
, make them explicit, and make it clear that this doesn't inherit
from anything.

(Unlike in b75908b, this handles the wrinkle of giving the
appropriate textBaseline for our Japanese support. See a recent
commit that added localizedTextBaseline.)

If we were defining this within the scope of the global `ThemeData`,
rather than outside it (to add to it), we might instead have aliased
the details like so:

  final theme = Theme.of(context);
  theme.textTheme.titleLarge!
    .apply(color: theme.colorScheme.onSurface);

, which is much simpler; oh, well. That `textTheme` is the result of
complicated computations based on Typography in [Theme.of], and
[Theme.of] only works when you're below the right [Theme] in the
widget tree.

Next, we'll change the `color`, `fontSize`, and `height` to align
with the Figma. (We couldn't have just passed a `TextStyle` with
those three fields by themselves, even with `inherit: true`. If you
give AppBar a TextStyle for the title like this, it just takes it
literally, in place of the default style that applies when you don't
give the TextStyle.)
I don't expect these to be fundamentally hard, they're just not
really trivial; we'll leave them for later.
It's possible that there's a different organization we may end up
preferring -- for example, if we find ourselves wanting to create
our own variables that are not in the Figma design. But this seems
like a helpful thing to try, for paving the way to implement the
Figma design.
…ange

In a recent commit in this series, we decreased the app-bar title
text size, to align with the new Figma.

The spacing and alignment in MessageListAppBarTitle for stream and
topic narrows looked a little off after doing that. This should make
it look better. I'm leaving the comment saying it's "a bit ad hoc",
though; this will remain true until we have a Figma design to
follow.
@chrisbobbe chrisbobbe force-pushed the pr-design-variables branch from ea91750 to 3a7ddc3 Compare June 17, 2024 23:20
@chrisbobbe chrisbobbe merged commit 02cb728 into zulip:main Jun 17, 2024
1 check passed
@chrisbobbe chrisbobbe deleted the pr-design-variables branch June 17, 2024 23:25
@chrisbobbe
Copy link
Collaborator Author

Thanks! Done.

@chrisbobbe
Copy link
Collaborator Author

chrisbobbe commented Jun 17, 2024

I think the behavior shown in the screenshots where the icon doesn't grow when the text is big is actually fine — it's normal and helpful that increasing text size doesn't cause the rest of the UI to expand, other than text.

Yeah; true. Maybe worth mentioning that we can apply custom scalers where we want to: for example, if we wanted to let icons respond to the text-size setting only when it's set smaller than the default 1x. But I agree not a priority for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration review Added by maintainers when PR may be ready for integration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants