Skip to content

feat(native): the Swift theme tints stock controls where the accent stays readable, and sets a single-mode theme's color scheme - #8290

Merged
cixzhang merged 9 commits into
mainfrom
native/swift-theme-tint
Oct 25, 2026
Merged

cixzhang merged 9 commits into
mainfrom
native/swift-theme-tint

Conversation

@cixzhang

@cixzhang cixzhang commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

What changes for people

Inside .astryxTheme(_:), SwiftUI's own controls carry the brand only through their tint, wherever it stays readable. A stock Toggle, ProgressView, Picker, Link, or borderless Button takes the theme's accent in any mode where white reaches 3:1 against it (stock controls draw white on their tint), and the system tint otherwise. A prominent button keeps its white label on that tint. The theme doesn't change stock controls' text colors, so links still look like links and filled buttons stay readable in every theme. A single-mode theme such as Gothic sets its section's color scheme, so stock surfaces inside draw dark on its dark grounds.

Decided by cixzhang, 2026-10-25: "Let's not affect Swift controls aside from tint."

What this does

Implements the theme environment spec's E2 (packages/native/specs/swift/library/theme-environment.md): .astryxTheme(_:) now also writes

  • .tint(_:) from color.accent in a mode where white meets 3:1 against it, else the system tint (WCAG's floor for interface components; the system's own dark blue is about 3.6:1);
  • for a single-mode theme (page ground, card ground, primary text, and accent the same in light and dark), the subtree's colorScheme, from its page ground, written without a view branch so switching themes keeps state.

The tint resolves where it is drawn, through a ShapeStyle that reads the color scheme there, so a subtree with its own color scheme gets that mode's tint (E3). An inner .astryxTheme(_:) replaces the outer tint (E5). Without the modifier nothing is written (E4). The theme writes no foreground style: an inherited one overrides stock controls' own label colors, turning links into plain text and prominent labels dark (shown below). The default font stays unset (the spec's open question).

Spec change

Theme environment E2: the tint row, the single-mode paragraph, the sentence that the theme affects stock controls only through the tint (with the decision), the E2 check row, and Current state. Measured white-on-accent contrast: default 5.39 light / 3.11 dark; butter 5.24 / 1.18; chocolate 5.88 / 2.32; matcha 9.77 / 1.70; neutral 17.22 / 1.13; stone 15.25 / 1.13; y2k 15.22 / 1.14; gothic 1.14 (single mode).

Captures (AST-093 FR5)

iPhone 16 simulator, iOS 18.5, Xcode 16.4. Stock controls (Link, borderless, bordered, prominent, Toggle, plain Text) under Core (top) and Neutral (bottom). Left to right: the earlier head that also wrote the text color, this change (tint only), and a variant that kept the text color. Built from 8d25940, this change's theme code before the rebase onto main, which changed no theme code.

This change alone, light and dark:

Astryx components are unchanged by this (they read the theme directly):

Not measured: the largest text size (tint is independent of text size) and the accessibility tree.

Testing

  • Tests: pale dark-mode accents (butter, chocolate, matcha, neutral, stone, y2k, gothic) leave stock controls the system tint, and every light accent keeps its tint; only Gothic is single-mode; Gothic in a light appearance draws a stock surface dark.
  • View tests: a .tint swatch under the default theme reads its accent in light and the passing dark accent; the theme leaves .primary exactly as the system draws it; a stock Link and a borderless Button draw their labels in the tint; a .borderedProminent label stays white on the tint; a nested .environment(\.colorScheme, .dark) inside a light theme reads the dark tint; an inner theme replaces the tint.
  • swiftc -typecheck of both modules, the tests, and the templates; the Swift tests run in CI on macOS and the iOS Simulator.

Every changed file is under packages/native/.

@vercel

vercel Bot commented Oct 24, 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 10:45pm UTC

Request Review

@astracat-bot

astracat-bot Bot commented Oct 24, 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, 11:18 PM UTC

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

github-actions Bot commented Oct 24, 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.

Changes requested: .astryxTheme(_:) picks light or dark once, where the modifier sits, so a subtree that sets its own color scheme below it keeps the other mode's tint and text colors; plain Text on an AstryxCard inside a dark section of a light butter screen draws at about 1.25:1 (Theme.swift, lines 241-247). Resolving the colors where they are drawn, for example with a ShapeStyle whose resolve(in:) reads environment.colorScheme, plus a test that sets .environment(\.colorScheme, .dark) inside .astryxTheme(.butter), would fix it. The tint and foreground writes themselves are defined only by the draft theme-environment spec, which AST-093 FR6 treats as a spec gap rather than a blocker.

[Automated review]

Comment on lines +244 to +247
let color = (colorScheme == .dark ? theme.dark : theme.light).color
content
.tint(color.accent)
.foregroundStyle(color.textPrimary, color.textSecondary, color.textDisabled)

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.

These colors are picked once, from the color scheme where .astryxTheme(_:) sits, and are fixed sRGB values, so a descendant with its own .environment(\.colorScheme, .dark) keeps the light accent and text colors while Astryx components beside it switch to dark tokens: plain Text on butter's dark card is #1D1C11 on #3A2A1F, 1.25:1. Resolving them where they are drawn, for example with a ShapeStyle whose resolve(in:) picks by environment.colorScheme, keeps the two in step; a Pixels test with .environment(\.colorScheme, .dark) inside .astryxTheme(.butter) would cover it.

@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 recommended: .astryxTheme(_:) now resolves the tint and text colors in the color scheme of the view that draws them, which fixes the earlier dark-section issue, and the new view tests cover it on macOS and the iOS Simulator. The tint and foreground writes follow the draft theme-environment spec (E2, E3, E5); until that record is current, AST-093 FR6 treats them as a spec gap rather than a blocker, so an engineering owner can approve this head once its required checks pass. Worth settling when that record becomes current: several themes' dark accents are near white (butter #FDEE8C, neutral #F1F1F1), where a stock control's own white label or thumb, such as a .borderedProminent button or the iOS switch, would sit at 1.13:1 to 1.18:1 against the tint; a device capture would confirm it.

[Automated review]

@cixzhang
cixzhang force-pushed the native/swift-theme-tint branch from f0b5fa0 to 0234a23 Compare October 24, 2026 20:10
@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec 0234a23

@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 recommended: .astryxTheme(_:) now writes SwiftUI's tint and foreground styles from the theme, resolved in the color scheme of the view that draws them, and the new view tests pass on macOS and the iOS Simulator. These writes follow the draft theme-environment record (E2, E3, E5), which an engineering owner approved on this head, so nothing more is needed here once the required checks pass. Worth settling when that record becomes current: what stock controls draw on a pale tint (white on butter's dark accent #FDEE8C is 1.18:1), SwiftUI's palette rendering of multi-layer SF Symbols under a three-level foreground style, and textDisabled as the tertiary level; device captures would confirm the first two.

[Automated review]

@cixzhang
cixzhang force-pushed the native/swift-theme-tint branch from 0234a23 to 7e826ea Compare October 24, 2026 21:00
@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec 7e826ea

@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 recommended: .astryxTheme(_:) now writes SwiftUI's tint and foreground styles from the theme, resolved in the color scheme of the view that draws them, and the new view tests pass on macOS and the iOS Simulator. No current spec defines these writes yet, so under AST-093 FR6 they are recorded as spec gaps rather than blockers, and nothing more is needed here once the required checks pass. Worth settling when the theme environment record becomes current:

  • Gothic is dark-only, so in a light system appearance stock text and tinted controls on system surfaces would draw #E8F1F6 at about 1.14:1 against white.
  • Stock controls that draw white on the tint would sit at 1.13:1 to 1.18:1 on the pale dark-mode accents of butter, neutral, stone, y2k and Gothic.
  • The three-level foreground style switches unstyled multi-layer SF Symbols to palette rendering and makes textDisabled the tertiary level.

[Automated review]

@cixzhang
cixzhang force-pushed the native/swift-theme-tint branch from 7e826ea to 3cab703 Compare October 25, 2026 04:13
@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec 3cab703

@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec 790635a

@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.

Changes requested: .astryxTheme(_:) writes Gothic's color scheme through an if let view branch (Theme.swift, lines 293-295), so an app that switches theme at runtime between Gothic and any other theme rebuilds everything inside the modifier and loses its state. Writing the scheme without branching, for example .transformEnvironment(\.colorScheme) { if let mode = theme.singleMode { $0 = mode } }, would fix it.

  • Please add a Pixels test for a stock Link and a borderless Button under the theme, because the theme's foreground style is expected to win over the tint for their labels while the description says they take the accent.
  • The Testing section still describes butter swatch tests, but on this head those tests use the default theme.

[Automated review]

Comment on lines +293 to +295
@ViewBuilder fileprivate func astryxSingleModeScheme(_ scheme: ColorScheme?) -> some View {
if let scheme { environment(\.colorScheme, scheme) } else { self }
}

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.

This if let makes the modifier's body a conditional view, so Gothic and every two-mode theme give the content different identities; switching theme at runtime between them rebuilds the whole subtree and resets its @State. An inert write keeps one structure for every theme, for example:

.transformEnvironment(\.colorScheme) { if let mode = theme.singleMode { $0 = mode } }

func body(content: Content) -> some View {
content
.tint(AstryxThemeColor(theme: theme, role: .tint))
.foregroundStyle(AstryxThemeColor(theme: theme, role: .textPrimary))

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.

This foreground style also reaches the labels of stock Links and borderless Buttons, and an explicit foreground style wins over the tint for them, so they are expected to draw in textPrimary rather than the accent the description promises. A Pixels test of each under .astryxTheme(.default) would settle it.

@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 of this head waits on one spec decision: E2 of the draft theme environment spec is reworded here (the 3:1 rule for .tint, the primary-only .foregroundStyle, the single-mode colorScheme paragraph and the E2 check row), no current spec states it, and the earlier /approve-spec for the same text names a different head. An engineering owner records the decision by commenting /approve-spec <full head SHA> on this pull request, and the author may do so if they are an engineering owner; otherwise please say which part of E2 should change. The code matches that text, and its tests pass on macOS and the iOS Simulator.

  • A Pixels test of a stock Link and a borderless Button under the theme would show whether their labels take the accent, as the description says, or the theme's primary text color, which the subtree-wide foreground style is expected to give them.
  • The Testing section describes butter swatch tests that use the default theme on this head, and the E2 and E5 check rows name a stock Toggle that those swatch tests do not draw.

[Automated review]

| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| E1, E3 | A view test with only `.preferredColorScheme(.dark)` (no other Astryx setting) draws an Astryx component with dark tokens; with `colorSchemeContrast` increased, a Card draws `color.borderEmphasized`. With `legibilityWeight` set to `.bold`, an Astryx Text in butter's registered body face at regular weight resolves to semibold, and at bold to heavy. |
| E2 | A stock SwiftUI `Toggle` inside `.astryxTheme(.butter)` draws butter's accent; a plain `SwiftUI.Text` inside it draws butter's primary text color. |
| E2 | A stock SwiftUI `Toggle` inside `.astryxTheme(.butter)` in light draws butter's accent, and in dark, where butter's pale accent fails 3:1 against white, the system tint; a plain `SwiftUI.Text` inside it draws butter's primary text color; under `.astryxTheme(.gothic)` in a light appearance, a stock surface draws dark. |

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.

This check names a stock Toggle and a plain SwiftUI.Text under .astryxTheme(.butter), but the tests on this head draw .tint and .primary swatches under .astryxTheme(.default) and check butter's dark fallback as a function (EnvironmentTests.swift:92-119); the E5 row below names a stock Toggle too. Describing the swatch tests here, or attaching simulator captures of the Toggle and Text, would make the check match its evidence.

@cixzhang

Copy link
Copy Markdown
Contributor Author

Posted by Cindy's agent on her behalf.

Decision (Cindy, 2026-10-25): the Swift theme does not affect stock SwiftUI controls except through the tint.

  • The theme no longer writes a root text (foreground) color, so stock links, borderless buttons and prominent button labels keep their system colors.
  • The tint is the theme's accent only in modes where white on it meets 3:1; otherwise it's the system tint.
  • A single-mode theme (such as Gothic) still sets its subtree's color scheme.
  • Astryx's own components keep using the theme's colors.

What this PR needs: the code and the E2 record on this head implement exactly that. It merges once CodeBunny and CI are clean and the spec approval is posted on the final head.

@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 of this head waits on one spec decision: E2 of the draft theme environment spec is rewritten here (the 3:1 rule for .tint, no foreground style, the single-mode colorScheme paragraph and the amended E2 check row), no current spec states it, and no /approve-spec names this head yet. An engineering owner records the decision by commenting /approve-spec <full head SHA> on this pull request, and the author may do so as an engineering owner; otherwise please say which part of E2 should change. Worth weighing first: in light mode the 3:1 rule keeps accents that equal or nearly equal body text as the tint (neutral #1B1B1B, stone #25252A, y2k #2D241B, matcha #3E481D), so stock links and borderless buttons read as plain text, as the Neutral capture in the description shows.

  • The record's Summary and E1 colorScheme row still say the system setting drives the mode and that stock controls take the theme's accent, so they need aligning with E2.

[Automated review]

| `.foregroundStyle(_:_:_:)` (primary, secondary, tertiary) | `color.textPrimary`, `color.textSecondary`, `color.textDisabled` |
| SwiftUI value | From the theme |
| ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| `.tint(_:)` | `color.accent`, in a mode where white meets 3:1 against it, because stock controls draw white on their tint; the system tint in any other mode |

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.

A stock Link or borderless Button draws its label in this tint, and the 3:1 test measures only white on the accent, so in light mode it keeps neutral #1B1B1B, stone #25252A, y2k #2D241B and matcha #3E481D, which equal or nearly equal body text. The Neutral light capture in the description shows the stock link and borderless button looking like plain text, the outcome the paragraph below gives as its reason for writing no foreground style.

| Requirement | Check |
| ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| E1, E3 | A view test with only `.preferredColorScheme(.dark)` (no other Astryx setting) draws an Astryx component with dark tokens; with `colorSchemeContrast` increased, a Card draws `color.borderEmphasized`. With `legibilityWeight` set to `.bold`, an Astryx Text in butter's registered body face at regular weight resolves to semibold, and at bold to heavy. |
| E2 | A stock SwiftUI `Toggle` inside `.astryxTheme(.butter)` in light draws butter's accent, and in dark, where butter's pale accent fails 3:1 against white, the system tint; a stock `Link` and a borderless `Button` draw their labels in the tint, and a prominent `Button` keeps its white label; under `.astryxTheme(.gothic)` in a light appearance, a stock surface draws dark. |

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.

This row names a stock Toggle inside .astryxTheme(.butter) in light and in dark, but the tests draw .tint swatches under .astryxTheme(.default) and check butter's dark fallback as a function (EnvironmentTests.swift:92-99, :135-145), and the description's captures show a Toggle under core and Neutral only. Describing that evidence here, or attaching a butter capture, would make the row match it.

@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 of this head waits on one spec decision: the rewritten E1 colorScheme row, E2 and E2 check row of the draft theme environment spec (the 3:1 rule for .tint, no foreground style, the single-mode colorScheme) are stated by no current spec, and no /approve-spec names this head yet. An engineering owner records the decision by commenting /approve-spec <full head SHA> on this pull request, and the author may do so as an engineering owner; otherwise please say which part of E2 should change. Worth weighing first: in light mode the 3:1 rule keeps accents that equal or nearly equal body text as the tint (neutral #1B1B1B, stone #25252A, y2k #2D241B, matcha #3E481D), so stock links and borderless buttons read as plain text, as the Neutral capture in the description shows. The code matches that text, and its tests pass on macOS and the iOS Simulator.

  • The title still says the theme sets foreground styles; it now sets only the tint and a single-mode theme's color scheme.

[Automated review]

@cixzhang
cixzhang force-pushed the native/swift-theme-tint branch from f7de15b to 81a4c0e Compare October 25, 2026 22:38
@cixzhang cixzhang changed the title feat(native): the Swift theme sets SwiftUI's tint and foreground styles feat(native): the Swift theme tints stock controls where the accent stays readable, and sets a single-mode theme's color scheme Oct 25, 2026

@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 of this head waits on one spec decision: the rewritten E1 colorScheme row, E2 and E2 check row of the draft theme environment spec (the 3:1 rule for .tint, no foreground style, the single-mode colorScheme) are stated by no current spec, and no /approve-spec names this head yet. An engineering owner records the decision by commenting /approve-spec <full head SHA> on this pull request, and the author may do so as an engineering owner; otherwise please say which part of E2 should change. Worth weighing first: in light mode the 3:1 rule keeps accents that equal or nearly equal body text as the tint (neutral #1B1B1B, stone #25252A, y2k #2D241B, matcha #3E481D), so stock links and borderless buttons read as plain text, as the Neutral capture in the description shows. The code matches that text, and its tests pass on macOS and the iOS Simulator.

[Automated review]

@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec 81a4c0e

@cixzhang
cixzhang merged commit 2626a47 into main Oct 25, 2026
74 checks passed
@github-actions
github-actions Bot deleted the native/swift-theme-tint branch October 26, 2026 06:31

This branch was successfully deployed

1 active deployment
Preview — 81a4c0eb 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