Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

spec(native): Swift contracts keep only props each platform honors; href draws a Link; no Swift stacks (#8269)

Cindy Zhang0cba39874f27
diff --git a/packages/native/specs/swift/library/augmentable-variants.md b/packages/native/specs/swift/library/augmentable-variants.md
index 2d74f498b7..c8cadeb8d7 100644
--- a/packages/native/specs/swift/library/augmentable-variants.md
+++ b/packages/native/specs/swift/library/augmentable-variants.md
@@ -19,7 +19,7 @@ draws the component's base look, with no value style, instead of failing.
## Requirements
- **V1 — An augmentable prop is an open, string-backed type.** For every prop
- the core contract marks augmentable, the contract generator emits a
+ the platform's contract keeps that the core contract marks augmentable, the contract generator emits a
`struct <Name><Prop>: RawRepresentable, Hashable, Codable, Sendable,
ExpressibleByStringLiteral` holding the web value as its raw string, instead
of a closed `enum`. Each built-in value is a static constant named by the
diff --git a/packages/native/specs/swift/library/component-api.md b/packages/native/specs/swift/library/component-api.md
index 0538a4d9a9..51c7f51f42 100644
--- a/packages/native/specs/swift/library/component-api.md
+++ b/packages/native/specs/swift/library/component-api.md
@@ -47,9 +47,8 @@ same generated contract.
module, an unqualified name means the Astryx type, so every use of a SwiftUI
type that Astryx also names is written with its own module. The Astryx
names visible under `import SwiftUI` today are `Button`, `ContextMenu`,
- `Divider`, `Grid`, `HStack`, `Layout`, `Link`, `List`, `Section`, `Slider`,
- `Stepper`, `Tab`, `Table`, `TableRow`, `Text`, and `VStack` (written
- `SwiftUI.<Name>`), `Calendar` and `Timer` (written `Foundation.<Name>`), and
+ `Divider`, `Grid`, `Layout`, `Link`, `List`, `Section`, `Slider`, `Stepper`,
+ `Tab`, `Table`, `TableRow`, and `Text` (written `SwiftUI.<Name>`), `Calendar` and `Timer` (written `Foundation.<Name>`), and
`Selector` (written `ObjectiveC.Selector`); a new component whose name any of
those modules declares joins this list.
- **A1c — Modifiers keep the prefix.** View modifiers live on SwiftUI's `View`
@@ -59,7 +58,12 @@ same generated contract.
platform prop of the generated `<Name>Props` for the platform being built
(`ios` on iOS, `macos` on macOS, such as Selector's `menuStyle`) is a
parameter of the view with the same name, the same generated type, and the
- same default. A `content` slot, which `<Name>Props` leaves out, is a
+ same default. The core contract holds only props every platform honors
+ (AST-082 FR3), and each one keeps its full meaning on every Apple device,
+ adapting per device where the device differs; a prop is never accepted
+ without that meaning (`architecture:public-component-api` INV2). A prop only
+ one platform can honor is that platform's prop, such as Switch's `size`,
+ which only macOS can honor with the system switch. A `content` slot, which `<Name>Props` leaves out, is a
parameter of both initializers instead: the labeled one takes it as a
`@ViewBuilder` closure and the props one as the slot's generated node type
(A3, A4). The view
@@ -84,6 +88,14 @@ same generated contract.
slot is an `IconName` field.
- Parameters without defaults come before those with defaults, except a
required action, which comes last so it can be a trailing closure.
+ - A prop whose native form is a different SwiftUI control switches the
+ control: with `href` set, Button, Avatar, and Item draw a SwiftUI `Link`, so the system opens it and VoiceOver reads it as a
+ link. Each keeps its own look: Button through the Astryx button style,
+ Avatar and Item as they draw without `href`. Disabled follows core: a
+ disabled Button with `href` draws its disabled button, not a link, as core
+ draws a disabled `<button>`; a disabled Item with `href` stays a link that
+ VoiceOver reads as dimmed and that does not open, as core keeps a disabled
+ link; Avatar has no disabled state.
- **A5 — Words and values take the contract's types.** A word prop is the
contract's `String`, and a value prop and its change callback are the
contract's two parameters, as AST-093 FR5 requires. A localizable spelling
@@ -102,6 +114,11 @@ same generated contract.
the core prop it maps to where one exists; a declaration with no core prop
(an initializer, a content slot, a style or modifier) names the contract
part it serves.
+- **A9 — Layout SwiftUI already provides is not offered.** The Swift public
+ API offers no HStack or VStack view; apps use SwiftUI's own stacks with
+ token spacing (`theme.space.s4`). A logic-core tree on an Apple host keeps
+ its `HStack` and `VStack` wire nodes (AST-082 FR19), which the logic host
+ draws with SwiftUI's stacks.
## Acceptance checks
@@ -112,22 +129,23 @@ same generated contract.
| A1b | A source check fails when a file in the module uses a name from the A1b list without its module qualifier where it means the system type. |
| A1c | A source check finds no public `View` extension member without the `astryx` prefix. |
| A2 | A source check fails when a components file declares an `enum` with the same cases as a generated enum, or a public parameter that is neither a prop of the generated `<Name>Props`, the `<Name>Props` value itself, nor a content slot of the contract. |
-| A2 | A compile test builds every view from its generated `<Name>Props` with every prop set, plus each content slot's generated node type, and through the labeled initializer with a builder for each content slot, on iOS and on macOS. |
+| A2 | A compile test builds every view from its generated `<Name>Props` with every prop set, plus each content slot's generated node type, and through the labeled initializer with a builder for each content slot, on iOS and on macOS. A source check finds no parameter that a view accepts and ignores; Switch's `size` exists on macOS only. |
| A3 | A test builds a view through each initializer with the same arguments and finds every `<Name>Props` field the same in both, comparing callbacks by invoking them. |
-| A4 | `AnyView` does not appear in the components module. |
+| A4 | `AnyView` does not appear in the components module. An enabled Button with `href` is a `Link` in the view tree and reads as a link to VoiceOver; a disabled Button with `href` reads as a dimmed button; an Avatar with `href` draws the same as without it. A disabled Item with `href` reads as a dimmed link and does not open. |
| A5 | The A2 source check passes: no public parameter outside the generated `<Name>Props` and the contract's content slots. |
| A6 | A source check finds no public SwiftUI `Color`, `Font`, `CGFloat` padding, or `*Style` parameter on a component; the contract's own visual props are allowed. |
| A7 | A UI test finds the view by its `id` and does not find it when `isHidden` is true. |
| A8 | DocC builds with no missing-documentation warning for a public component symbol. |
+| A9 | The `Astryx` product declares no public `HStack` or `VStack` view; the logic host draws `HStack` and `VStack` wire nodes with SwiftUI's stacks. |
## Current state
-- On `main`, the only Swift package is `packages/native/apple`, whose product
- and module are `AstryxNative`: generated contract types and no SwiftUI views.
- Under A1 the library product apps depend on is `Astryx`, the module that
- holds the views and re-exports the contract module.
-- The generated contracts already use core names unprefixed (`ButtonProps`,
- `ButtonVariant`).
+- `packages/native/apple/` is one Swift package with the `Astryx` product
+ (SwiftUI views, prefixed `AstryxButton` and so on) and the `AstryxNative`
+ product (generated contract types). The generated contracts already use core
+ names unprefixed (`ButtonProps`, `ButtonVariant`).
+- The generated iOS `SwitchProps` still declares `size`, and `HStackProps` and
+ `VStackProps` are still generated for iOS and macOS.
## Open questions
diff --git a/packages/native/specs/swift/library/theme-environment.md b/packages/native/specs/swift/library/theme-environment.md
index fa6dc548dd..c89a141ac1 100644
--- a/packages/native/specs/swift/library/theme-environment.md
+++ b/packages/native/specs/swift/library/theme-environment.md
@@ -41,9 +41,10 @@ Astryx adds no second settings system for an app to keep in step.
So stock SwiftUI controls (`Toggle`, `Picker`, `ProgressView`, `Menu`,
`List`, `Slider`, `Link`) draw with the brand's accent and text colors.
- Whether the theme also sets the default font is OQ1. Theme values with no SwiftUI environment equivalent are read only
- by Astryx components and Astryx's SwiftUI styles: corner radius, spacing,
- element heights, borders, and backgrounds. Control size has no clean mapping: Astryx sizes are a per-
+ Whether the theme also sets the default font is OQ1. Theme values with no SwiftUI environment equivalent are read by
+ Astryx components and Astryx's SwiftUI styles (corner radius, spacing,
+ element heights, borders, and backgrounds), and an app reads spacing for its
+ own SwiftUI stacks from the typed tokens (`theme.space.s4`). Control size has no clean mapping: Astryx sizes are a per-
component prop, so the theme sets no `controlSize`.
- **E3 — The mode always follows SwiftUI.** A token value is chosen from the
diff --git a/packages/native/specs/swift/library/theme-generator.md b/packages/native/specs/swift/library/theme-generator.md
index 8d8608a3b8..e5a638266f 100644
--- a/packages/native/specs/swift/library/theme-generator.md
+++ b/packages/native/specs/swift/library/theme-generator.md
@@ -35,7 +35,7 @@ re-implements theme logic.
a native build script, each listed in the boundary check; once the portable
entry ships, it reads core only through that entry.
- **G3 — One shared token type, one file per theme.**
- - `swift-ios-1/core/Theme/Generated/Tokens.swift` declares the typed
+ - `apple/Sources/Astryx/Theme/Generated/Tokens.swift` declares the typed
token surface: `Tokens` with one member per group (`color`, `space`,
`radius`, `size`, `font`), each a struct with one typed member per token.
It is generated from core's resolved token names, which are the same for
@@ -43,7 +43,7 @@ re-implements theme logic.
- Type names follow the Swift component API spec: unprefixed, in the
`Astryx` module, so `Astryx.Theme.neutral` and `Theme.neutral` name the
same value.
- - Each theme becomes `swift-ios-1/core/Theme/Generated/<SwiftName>Theme.swift`,
+ - Each theme becomes `apple/Sources/Astryx/Theme/Generated/<SwiftName>Theme.swift`,
which declares `Theme.<swiftName>` with a `Tokens` value for
light and one for dark.
- `<swiftName>` is the theme's `name` with a leading `astryx-` removed, in
@@ -193,11 +193,11 @@ re-implements theme logic.
## Current state
-- `packages/native/` has generated contract types for Apple platforms
- (`apple/`) and no Swift theme types or theme generator.
-- The SwiftUI view package (`swift-ios-1/`) is added separately with a
- generator for core's default theme only, written as string-keyed token
- dictionaries; this spec describes the generator it grows into.
+- `packages/native/apple/` is one Swift package with the `AstryxNative`
+ product (generated contract types) and the `Astryx` product (SwiftUI views).
+- The generator writes the typed `Tokens.swift` and one theme file for core's
+ defaults and each published theme package (`Theme.default`, `Theme.neutral`,
+ and so on), under `apple/Sources/Astryx/Theme/Generated/`.
- Core's `resolveThemeTokens` returns shared tokens per mode and no local
tokens; neutral declares local tokens, stored as `light-dark(…)` strings.
- Published theme packages: butter, chocolate, gothic, matcha, neutral, stone,