Skip to content

feat(native): Swift font tokens group by type style and scale - #8418

Merged
cixzhang merged 2 commits into
mainfrom
native/swift-font-type-groups
Oct 25, 2026
Merged

cixzhang merged 2 commits into
mainfrom
native/swift-font-type-groups

Conversation

@cixzhang

@cixzhang cixzhang commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Swift font tokens now come grouped the way people use them: each type style holds its size, weight, and line height together (tokens.font.body.size, tokens.font.heading1.weight), and the family, size, and weight scales sit under their own names (tokens.font.family.body, tokens.font.size.s2xl, tokens.font.weight.bold).

Who it helps: app developers styling SwiftUI views from an Astryx theme. Before, FontTokens held 63 flat members (bodySize, bodyWeight, bodyLeading, heading1Size, …), so you had to read three members to build one style, and autocomplete was a wall of names. Now font.body is one value you pass whole, and a theme that leaves out part of a style fails generation with the style's name instead of compiling with a hole.

What changes

  • Generator (G3, G6): text-<style>-<part> → font.<style>.<part> with one TypeStyleTokens struct (size, weight, leading) per style: body, code, display1–3, heading1–6, label, large, supporting. font-family-<name> → font.family.<name>. font-size-<name> and font-weight-<name> → font.size.<name> and font.weight.<name>. A name that starts with a digit takes s, as space.s4 does (font.size.s2xl). A style missing its size, weight, or leading fails the run, naming the style.
  • Regenerated Tokens.swift and every theme file.
  • Views: Text and Heading read the grouped tokens. TypeStyle(font.body, families: font.family.body) builds a style. Two helpers move onto their scales: font.size.value(for:) and font.weight.value(named:).
  • Spec: theme-generator.md G3 (the font struct's shape), the G6 table, the G6 verification row, and Current state. README token example.
@Environment(\.astryx) var astryx
let body = astryx.tokens.font.body           // TypeStyleTokens
Text("Total").font(.system(size: body.size * astryx.textScale))
astryx.tokens.font.family.heading            // ["-apple-system", …]
astryx.tokens.font.size.s2xl                 // 24

This is Cindy's decision: "For fonts those tokens are complex so I'd rather have it grouped by type."

Existing authority searched

Search terms: FontTokens, font.bodySize, text-<style>-<part>, TypeStyle, font-family, theme-generator G3/G6. Records found: the Swift theme generator spec (G3, G6), which this pull request amends. Overlapping open pull requests inspected: #8307, #8308, #8310 (Swift views stack; they read flat font members and rebase onto this), and the Swift theme CSS-value converter (in progress; it touches the generator's value parsing, not the token surface). No other record defines the Swift font token shape.

Writing rubric results

  • R1 present tense: the amended G3/G6 text and Current state describe the system as it is.
  • R2 research in the record: none.
  • R3 evidence naming a change: none. The verification row names checks, not pull requests.
  • R4 rejected alternatives: one clause, the reason for grouping ("each type style is several tokens a view reads together").
  • R5 user impact first: the summary leads with the developer reading a style whole.
  • R6 open questions: none added.

Tests

  • vitest run packages/native/src: 52 passed. Covers the G6 cases for every font form, a grouped Tokens.swift, a style missing its leading failing with its name, and the drift test against the committed Swift.
  • tsc --noEmit for the native package.
  • swiftc -typecheck of AstryxNative, Astryx, the tests, and the templates. Text and Heading tests read the grouped tokens.
  • pnpm check:knowledge.
  • Captures (FR5) below: no visual change. Text and Heading draw the same values, read through the grouped members.

Captures (AST-093 FR5)

iPhone 16 simulator, iOS 18.5, Xcode 16.4, built from this PR's head (a580e77): every Text type, size, weight and color; Heading levels, display types, justify, and maxLines; light, dark, and the largest text size (AX5, top and end).

Accessibility tree: not measured. The captures show pixels; the Swift tests check the accessible names.

@vercel

vercel Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Oct 25, 2026 4:34pm UTC

Request Review

@astracat-bot

astracat-bot Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
❓ Needs maintainer input (for maintainers only) Oct 25, 2026, 4:50 PM UTC

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 25, 2026
@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec d7bdff4

@github-actions

github-actions Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR

🧪 Sandbox Preview

View Sandbox for this PR

No new or modified components detected.

Bundle Size Summary

No component packages changed.

Accessibility Audit

Status: No accessibility violations detected.

Visual Regression

48 of 502 shot(s) changed.

A change here is a question, not a failure: check whether the after is the
picture you intended. Record that review on the PR. Baseline maintenance is an
explicit dispatch of CI; this report never rewrites the baseline or adds a release gate.

component story theme mode pixels
Selector Indicator Space Bottom Sheet Narrow End RTL neutral light 753,933
Selector Indicator Space Bottom Sheet Wide Start neutral light 740,072
RichTextEditor Markdown parity: side by side probe dark 556,900
RichTextEditor Markdown parity: side by side probe light 538,816
Chat Full AI Chat probe light 230,823
Chat Full AI Chat probe dark 229,805
AppShell With Mobile Nav probe light 217,010
AppShell With Mobile Nav probe dark 216,960
Collapsible Dividers probe dark 66,445
Collapsible Dividers probe light 66,445
AppShell Playground neutral dark 65,198
AppShell Playground neutral light 63,788
Chat Default neutral dark 36,304
Chat Default neutral light 35,767
Chat Empty State probe light 23,531
Chat Empty State probe dark 22,622
ChatAutoScroll Scroll Behavior Comparison neutral dark 15,378
ChatAutoScroll Scroll Behavior Comparison neutral light 14,107
Chat With Attachments probe light 13,406
Chat With Attachments probe dark 11,232

and 28 more.


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Requesting changes: the grouped Swift font tokens match the owner-approved theme generator spec and every generated value is unchanged, but two items need fixing first.

  • Attach the AST-093 FR5 captures of Text and Heading from this head in light, dark, and the largest text size, or mark any state you could not capture as not measured, so the no-visual-change claim rests on captures rather than source.
  • In packages/native/specs/swift/library/theme-generator.md, the G10 acceptance row still names font.familyBody; it should be font.family.body.

[Automated review]

| `radius-<rest>` | `radius.<rest>`: `radius-element` → `radius.element` |
| `size-element-<rest>`, `border-width` | `size.element<Rest>`: `size-element-md` → `size.elementMd`; `size.borderWidth` |
| `text-<style>-<part>` | `font.<style>.<part>`, one `TypeStyleTokens` per style with `size`, `weight`, and `leading`: `text-body-size` → `font.body.size`, `text-heading-1-weight` → `font.heading1.weight` |
| `font-family-<rest>` | `font.family.<rest>`: `font-family-body` → `font.family.body` |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Renaming the family members to font.family.<rest> here leaves the G10 acceptance row (line 163) naming font.familyBody, which no longer exists; please update that row to font.family.body in this pull request.

@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec a580e77

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approval now waits on an engineering owner's decision: the rewritten G3, G6 and G10 text in the draft packages/native/specs/swift/library/theme-generator.md was approved on the previous head, and the G10 fix commit invalidated that approval. Any engineering owner, including the author if they are one, can record the decision by commenting /approve-spec a580e77860c3e8fad22adeb6c8f6f082ffd6c521 on this pull request, or say what the Swift font token shape should be instead. Separately, AST-093 FR5 still needs captures of Text and Heading in light, dark and at the largest text size attached to the change, or each state you could not capture (and the rendered tree's accessibility) reported as not measured in the description; the regenerated token values themselves are unchanged.

[Automated review]

@cixzhang
cixzhang merged commit c26ae3f into main Oct 25, 2026
71 checks passed
@github-actions
github-actions Bot deleted the native/swift-font-type-groups branch October 26, 2026 06:31

This branch was successfully deployed

1 active deployment
Preview — a580e778 Deployed Oct 25, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant