Skip to content

spec(native): the Swift theme rides on SwiftUI's environment both ways - #8040

Merged
cixzhang merged 1 commit into
mainfrom
spec/native-swift-theme-environment
Oct 24, 2026
Merged

cixzhang merged 1 commit into
mainfrom
spec/native-swift-theme-environment

Conversation

@cixzhang

@cixzhang cixzhang commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Exact decision needed

How an Astryx theme rides on SwiftUI's environment in both directions: settings are read from SwiftUI (color scheme, contrast, text size, motion, transparency, direction, Bold Text) and never duplicated, and the theme writes SwiftUI's own values (tint, foreground styles, default font) so stock controls carry the brand. Draft until the owner approves; nothing is built from it before then.

Existing authority searched

  • spec:AST-093 FR3 (Apple platforms follow the HIG) and FR4 (brand through the theme); spec:AST-082 FR10 (native theme) and FR11 (platform controls and settings first).
  • The approved Swift theme generator spec produces the Theme and Tokens this spec carries; the approved Swift component API spec sets the names.
  • Today the theme modifier reads color scheme and text size only and writes no SwiftUI value; without it, components stay light in dark mode.

Decision

  • E1 Settings come from SwiftUI's environment (colorScheme, colorSchemeContrast, dynamicTypeSize, accessibilityReduceMotion, accessibilityReduceTransparency, layoutDirection, legibilityWeight); no Astryx mode API.
  • E1 also: under Bold Text, a custom face from the theme's family list is drawn one weight step heavier, since only system and text-style fonts follow legibilityWeight by themselves.
  • E2 .astryxTheme(_:) writes .tint (accent) and .foregroundStyle primary/secondary/tertiary (text colors); whether it also sets the default font is OQ1. Radius, spacing, heights, borders, backgrounds and control size have no SwiftUI equivalent and stay Astryx-only.
  • E3 The mode is read where a token is read, so subtree color schemes work.
  • E4 Without the modifier, components use core's default theme and still follow SwiftUI's settings.
  • E5 Subtrees can change theme, including E2's writes.
  • E6 One @Entry environment value; no singletons.

Rejected alternatives

None recorded in the spec.

Landing order

This builds on packages/native/specs/swift/library/theme-generator.md (#8031, with the unprefixed names from #8038) and packages/native/specs/swift/library/component-api.md (#8035). It lands after them; the library/ index entry is added when it is rebased onto those.

Claim scope and non-goals

Typed tokens and the theme files are the theme generator spec. Shipping Astryx's look as SwiftUI style protocols is a separate decision.

Evidence and implementation relationship

One file: packages/native/specs/swift/library/theme-environment.md.

Writing rubric results

  • R1 narration: none.
  • R2 research in the record: none.
  • R3 evidence naming a change: none.
  • R4 rejected alternatives: none.
  • R5 pull request or issue references remaining: none in the record.
  • R6 ruled open questions still listing options: none; OQ1 is unanswered with one recommendation.

Scope

  • Specification only; no implementation.
  • Every changed file is under packages/native/.
  • Public text contains no internal context.

@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 24, 2026 10:08am UTC

Request Review

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

astracat-bot Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Oct 24, 2026, 10:24 AM UTC

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

Previews ready: Storybook and Sandbox were built with this PR's docsite. CI evidence will be added when available.

View Storybook for this PR · View Sandbox for this PR

@cixzhang
cixzhang marked this pull request as ready for review October 24, 2026 03:26
@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec f4bc6be

@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: the approved direction stands, but the theme environment record needs four corrections before it merges.

  • The Current state section describes a Swift theme modifier and SwiftUI components that main does not have yet; describe main as it is, or land after the implementation and match it (components there already follow Dark Mode without the modifier).
  • The record builds on the theme generator and component API specs and a Dynamic Type spec that are not on main; land it after them, cite each by path, and add it to the library index.
  • E2 already requires the default-font write that OQ1 still asks about, so settle it one way.
  • E1 says Bold Text is followed because weights come from system or text-style fonts, but E2 installs the theme's custom body face; say how that face follows legibilityWeight and add a Bold Text check.

Because a new commit invalidates the current /approve-spec, an engineering owner will need to post it again for the corrected head.

[Automated review]

Comment on lines +74 to +79
- The theme modifier chooses light or dark tokens from `colorScheme` and scales
text from `dynamicTypeSize`; without the modifier, components use core's
default light tokens even in dark mode.
- The modifier writes no SwiftUI value, so stock SwiftUI controls inside an
Astryx theme keep the system accent and font.
- No component reacts to Increase Contrast, Reduce Transparency, or Bold Text.

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.

On main there is no Swift theme modifier or SwiftUI component yet: packages/native/apple holds the generated props, the wire and the logic host only. The modifier described here is in the open implementation #7981, where components already follow Dark Mode without it (EnvironmentValues.astryx picks the default theme's dark tokens). Describe main as it is, or land after #7981 and match its behavior.

Comment on lines +4 to +6
- Relation: extends AST-093 FR4 and AST-082 FR10, FR11; builds on the Swift
theme generator spec (the `Theme` and `Tokens` it generates) and the Swift
component API spec (names).

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.

The theme generator and component API specs this line builds on are not on main yet: the generator is #8031 (the unprefixed Theme and Tokens come from #8038, stacked on it) and the component API is #8035. Land after them and cite each by path, and add this file to the library/ index that #8031 introduces. The "library spec on Dynamic Type" on line 27 is not on main or in those pull requests either.

| `accessibilityReduceMotion` | Movement becomes a cross-fade or no animation |
| `accessibilityReduceTransparency` | Translucent surfaces become opaque |
| `layoutDirection` | Leading and trailing follow it |
| `legibilityWeight` | Bold Text: weights come from system or text-style fonts, so they follow it |

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.

With E2's default font, a registered custom body face (butter's Outfit) is neither a system nor a text-style font, so it does not get heavier under Bold Text on its own. Say how the family reader follows legibilityWeight for a custom face, or narrow this row to system faces, and add a Bold Text check to the acceptance table.

Comment on lines +83 to +86
- **OQ1 — Should the theme set the default font for all text in its subtree?**
It brands stock SwiftUI text, and it also changes text an app draws itself.
Recommendation: set it, because a theme's typeface is part of its identity
and an app can still set its own `.font(_:)` on any view.

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.

E2 (line 40) already requires the theme to set the default font, and the E2 check on line 67 tests it, so this question is answered there. Either fold this reason into E2 and drop OQ1, or move the font row and its check out of E2 until it is decided.

@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 waits on an engineering owner's decision: E1–E6 and their acceptance checks in theme-environment.md are new requirements that no current spec states, and the earlier /approve-spec named a head this push replaced. Any engineering owner, the author included, records that decision by commenting /approve-spec <full head SHA> on the head that will merge. Two fixes should land before that head:

  • The Bold Text rule says "one weight step heavier" but maps regular to semibold and gives no weight for medium, core's label weight, so spell out every weight and name the expected one in the E1 check.
  • The record cites theme-generator.md and component-api.md, which are not on main yet, so rebase onto those specs and add this file to the library/ index.

[Automated review]

| `accessibilityReduceMotion` | Movement becomes a cross-fade or no animation |
| `accessibilityReduceTransparency` | Translucent surfaces become opaque |
| `layoutDirection` | Leading and trailing follow it |
| `legibilityWeight` | Bold Text: system and text-style fonts follow it by themselves; a custom face from the theme's family list is drawn one weight step heavier when it is `.bold` (regular → semibold, semibold → bold, bold → heavy) |

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.

Regular → semibold is two steps on SwiftUI's Font.Weight scale (regular, medium, semibold) and on core's weight tokens (400, 500, 600), so "one weight step heavier" and this mapping disagree, and medium (core's --text-label-weight) has no entry. Spelling out the mapping for 400, 500, 600 and 700, and naming in the E1 check on line 66 the weight butter's body and label faces resolve to, would make the rule testable.

Comment on lines +4 to +7
- Relation: extends AST-093 FR4 and AST-082 FR10, FR11; builds on
`packages/native/specs/swift/library/theme-generator.md` (the `Theme` and
`Tokens` it generates, and its font family reader) and
`packages/native/specs/swift/library/component-api.md` (names).

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.

Neither theme-generator.md nor component-api.md exists on main or in this head yet (they are in #8031 and #8035, with the Theme/Tokens names from #8038). Rebasing onto them once they land, and adding this file to the library/ index, keeps these references resolvable.

@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec 609ddaa

@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec 2b5995d

@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: E1–E6 are owner-approved on this head, but the record still builds on theme-generator.md and component-api.md, which are not on main yet, so merging it now would leave the Relation line (lines 4–7) pointing at files that do not exist. Once #8031, #8038 and #8035 land, rebase onto them and add this file to the swift/library/ index; that new head needs a fresh /approve-spec <full head SHA> from an engineering owner, which the author can post.

[Automated review]

@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec fd40bc7

@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: E1–E6 are owner-approved on this head and the theme generator spec has landed, but the Relation line (lines 4–7) still names Theme and Tokens, which theme-generator.md on main calls AstryxTheme and AstryxTokens, and cites component-api.md, which is not on main yet. Rebase once #8035 and #8038 land, as the description plans, or cite the names main has today; either way the new head needs a fresh /approve-spec <full head SHA> from an engineering owner, which the author can post. While editing, consider a check with a stock Toggle and a plain Text under a subtree's own .environment(\.colorScheme, .dark), since no current check shows E2's tint and foreground styles following E3.

[Automated review]

Comment on lines +4 to +7
- Relation: extends AST-093 FR4 and AST-082 FR10, FR11; builds on
`packages/native/specs/swift/library/theme-generator.md` (the `Theme` and
`Tokens` it generates, and its font family reader) and
`packages/native/specs/swift/library/component-api.md` (names).

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.

On main, theme-generator.md generates AstryxTheme and AstryxTokens (G3), and component-api.md does not exist yet; Theme, Tokens and that file arrive with #8038 and #8035, which are still open. Rebase once they land, or cite the names main has today; either way the new head needs a fresh /approve-spec.


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

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 sets only .preferredColorScheme(.dark), which applies to the whole presentation, so no check shows E2's tint and foreground styles following a subtree's own .environment(\.colorScheme, .dark) as E3 (lines 49–52) says tokens do. A stock Toggle and a plain Text in such a subtree inside a light .astryxTheme(.butter) would cover it.

@cixzhang
cixzhang force-pushed the spec/native-swift-theme-environment branch from fd40bc7 to 820b786 Compare October 24, 2026 10:00
@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec 820b786

@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: an engineering owner approved E1–E6 on this exact head, the record contradicts no current native spec, and the Relation line and library index now resolve on main. Two small, non-blocking suggestions for a later edit:

  • Add a check that the theme's tint and foreground styles follow a subtree's own .environment(\.colorScheme, .dark), as E3 says tokens do, for example a stock Toggle and a plain SwiftUI.Text in a dark panel inside a light .astryxTheme(.butter).
  • Lines 44–46 list backgrounds as having no SwiftUI environment equivalent, but backgroundStyle(_:) is one, so either state keeping backgrounds Astryx-only as a choice or write it from color.backgroundSurface.

[Automated review]

| `legibilityWeight` | Bold Text: system and text-style fonts follow it by themselves; a custom face from the theme's family list is drawn heavier when it is `.bold`: ultra light → thin, thin → light, light → regular, regular → semibold, medium → semibold, semibold → bold, bold → heavy, heavy → black, black stays black |

- **E2 — The theme writes SwiftUI's own values where a native equivalent
exists.** `.astryxTheme(_:)` sets, for the subtree, in the current 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.

Written "in the current mode" where the modifier sits, these values do not follow a descendant's own .environment(\.colorScheme, .dark): that subtree's Astryx components switch to dark tokens (E3) while its stock Toggle keeps the outer accent and a plain Text the outer color.textPrimary. Saying E2's values follow the colour scheme where they are drawn (iOS 17's ShapeStyle.resolve(in:) can do it) keeps the two in step; a check with a stock Toggle and a plain SwiftUI.Text in such a subtree would prove it.

Comment on lines +44 to +46
Whether the theme also sets the default font is OQ1. Theme values with no SwiftUI environment equivalent are read only
by Astryx components: corner radius, spacing, element heights, borders, and
backgrounds. Control size has no clean mapping: Astryx sizes are a per-

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.

SwiftUI does carry a background style in the environment: backgroundStyle(_:) sets the style that background() and background(in:) fill with. If backgrounds stay Astryx-only, state it as a choice with its reason; or have .astryxTheme(_:) also write backgroundStyle from color.backgroundSurface so a stock background(in:) matches the theme.

@cixzhang
cixzhang merged commit 50df977 into main Oct 24, 2026
69 checks passed
@github-actions
github-actions Bot deleted the spec/native-swift-theme-environment branch October 25, 2026 06:20

This branch was successfully deployed

1 active deployment
Preview — 820b7862 Deployed Oct 24, 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