Repository navigation
feat(native): SwiftUI views as the Astryx product in apple/, with core components and clone-only templates - #7981
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report📚 Storybook Preview🧪 Sandbox PreviewNo new or modified components detected. Bundle Size SummaryNo component packages changed. Accessibility AuditStatus: No accessibility violations detected. Visual Regression46 of 498 shot(s) changed. A change here is a question, not a failure: check whether the after is the
and 26 more. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
There was a problem hiding this comment.
Approval is waiting on a maintainer. AST-082 FR5 and FR16 say Swift bindings and native platform contracts are generated from core's contracts and read core only through a portable entry, so a maintainer needs to update AST-082, or identify the record that allows swift-ios-1's hand-written SwiftUI parameters and its build-time import of @astryxdesign/core/theme. A maintainer also needs to provide or identify the governing spec for native templates shipped as the AstryxTemplates product, since AST-082 lists product templates as a non-goal. Whatever that decision, these still need changes:
AstryxTextshould defaultsupportingtext to the secondary colour and spell core'sxsmsize.xsm, as core's Text does.pnpm -F @astryxdesign/native generate:swift-iosfails on a fresh checkout until core is built, so the script should build core first.- The theme generator silently drops
--color-tint-hover, andAstryxButtonguarantees a 44 pt tap height but not width. - Please add a
swift buildandswift testrun and an iOS build of the package, or the planned macOS CI lane, before approval.
[Automated review]
| "prepack": "pnpm build", | ||
| "build": "node ../../scripts/clean-dist.mjs && tsc --project tsconfig.build.json && node scripts/generate.mjs --types", | ||
| "generate:apple": "pnpm build && node scripts/generate.mjs --apple", | ||
| "generate:swift-ios": "node scripts/swift-ios-theme.mjs", |
There was a problem hiding this comment.
On a fresh checkout this fails with ERR_MODULE_NOT_FOUND for @astryxdesign/core/dist/theme/index.js, because plain node resolves core's default export to dist/ and nothing builds it. The drift test's message sends contributors here. Building first, as generate:apple does, fixes it:
"generate:swift-ios": "pnpm -F @astryxdesign/core build && node scripts/swift-ios-theme.mjs"| /// Core's `Text` sizes this package draws so far, used to override the size | ||
| /// a semantic type sets. | ||
| public enum AstryxTextSize: String, CaseIterable, Sendable { | ||
| case xs |
There was a problem hiding this comment.
Core's Text size has no xs. The value is 'xsm', which maps to --font-size-xs (packages/core/src/Text/text.stylex.ts), so size="xsm" has no Swift spelling. Rename the case to xsm and keep the token font-size-xs, so the README's "core's prop names and values" holds (AST-082 FR3).
| public init( | ||
| _ content: String, | ||
| type: AstryxTextType = .body, | ||
| color: AstryxTextColor = .primary, |
There was a problem hiding this comment.
Core defaults Text color by type: supporting gets secondary, every other type primary (defaultColorByType in Text.tsx). With .primary here, AstryxText("…", type: .supporting) paints primary text. Making color optional and resolving it from type keeps the default the same on both platforms (AST-082 FR3).
| : parseFloat(m[4]); | ||
| return `#${hex2(+m[1])}${hex2(+m[2])}${hex2(+m[3])}${hex2(alpha * 255)}`; | ||
| } | ||
| if (v === 'transparent') return '#00000000'; |
There was a problem hiding this comment.
Any other CSS keyword returns null, and resolveMode then skips the token without a message. Core's --color-tint-hover resolves to black / white, so it is missing from both generated tables, and the drift test cannot notice. Accept CSS named colours, or throw on an unreadable value in a kept group.
| .opacity(isEnabled ? (configuration.isPressed ? 0.75 : 1) : 0.5) | ||
| // Drawn at the token height; laid out at least 44 high so the whole | ||
| // platform-minimum tap area counts. | ||
| .frame(minHeight: 44) |
There was a problem hiding this comment.
This guarantees the 44 pt minimum vertically only. A one-character label is about 33 pt wide (label plus 2 × 12 pt padding), below the minimum the doc comment promises (AST-082 FR11). .frame(minWidth: 44, minHeight: 44) covers both.
6f39984 to
ca4564f
Compare
ca4564f to
a3dc848
Compare
067933a to
8a5924b
Compare
There was a problem hiding this comment.
Approval is waiting on an engineering owner's decision: AST-093 FR5 asks native components to take parameters named and typed as their generated contracts (ButtonProps, TextProps, HeadingProps, TextInputProps and CardProps already exist), and AST-082 FR16 lets native read core only through a portable entry, but swift-ios-1 hand-writes its initializers and its theme generator imports @astryxdesign/core/theme. An engineering owner can accept that interim shape by commenting /approve-spec <full head SHA> on this pull request (the author may, as an engineering owner) or by amending AST-093 or AST-082; otherwise the components move onto the generated contracts, Banner gets one, and the generator waits for the portable entry. Whatever that decision, these need changes:
AstryxButtontreatsisLoadingas disabled (dimmed to 0.5 and.disabled), where core's Button stays undimmed, focusable and announces Loading.- AST-093 FR5's evidence is missing: accessibility and largest-Dynamic-Type checks, tests for Heading, TextInput and Banner, a test run on iOS, and simulator or device captures.
- The type family and Banner icons are fixed in code (
.systemfonts,--font-family-*dropped by the generator), so a theme's font and icons never reach iOS (AST-093 FR4). - Outside
.astryxTheme()the components ignore Dark Mode and Dynamic Type (AST-082 FR11).
[Automated review]
| ) | ||
| // A loading button keeps its label for VoiceOver, and the progress | ||
| // indicator announces itself; taps are ignored until it finishes. | ||
| .disabled(isDisabled || isLoading) |
There was a problem hiding this comment.
isLoading makes the button disabled, so the style dims it to 0.5 (line 132) and assistive technology gets a disabled control. Core's Button keeps a loading button undimmed and focusable and announces Loading through a live region, and family:buttons FR4 keeps disabled and pending styling distinct. Disable only for isDisabled, ignore taps in the action while loading, and overlay the spinner so the width holds.
|
|
||
| /// A system font at a token size and a token weight. | ||
| public func font(size token: String, _ fallback: CGFloat, weight: String) -> Font { | ||
| .system(size: fontSize(token, fallback), weight: fontWeight(size(weight, 400))) |
There was a problem hiding this comment.
Every component's font is .system, and the generator drops --font-family-*, so a theme's type family never reaches iOS. AST-093 FR4 lists type family among the values that come from the theme; carry the family tokens and use Font.custom when the first family is installed, keeping the system font for a system stack.
| } | ||
|
|
||
| private struct AstryxStyleKey: EnvironmentKey { | ||
| static let defaultValue = AstryxStyle(tokens: .defaultLight) |
There was a problem hiding this comment.
Without .astryxTheme() this default keeps light colours in Dark Mode and a text scale of 1, so text ignores Dynamic Type (AST-082 FR11). Keeping the theme in the environment and resolving mode and scale where components read it would let the default follow both settings.
| const {defineTheme} = await import('@astryxdesign/core/theme'); | ||
| const {resolveThemeTokens} = await import('@astryxdesign/core/theme/tokens'); |
There was a problem hiding this comment.
This reads core's web theme entry, which exports Theme and the CSS generators, where AST-082 FR16 lets native read core only through a portable entry. check-package-boundaries.js does not see it because it scans only packages/native/src. This is part of the open owner decision on the interim shape.
|
/approve-spec d2ada10 |
|
/approve-spec b5e5eef |
|
/approve-spec 846a9ea |
There was a problem hiding this comment.
Changes are needed before this can be approved. An engineering owner's /approve-spec on this head settles the interim direction, but AST-093 FR5 and AST-082 FR3/FR16 still say the opposite, and AST-093 FR5's evidence is incomplete.
- Attach iOS Simulator or device captures of every component state and of the login template's rest, error and loading states, in light, dark and at the largest text size (AST-093 FR5).
- Record the accepted interim shape on
main(AST-093 FR5 for the hand-written parameters and Banner's missing contract, AST-082 FR16 for the build-time@astryxdesign/core/themeimport), or move Button, Text, Heading, TextInput and Card onto their generated contracts. - Run the Swift tests on an iOS Simulator and add the missing checks: Heading at the largest text size and under a second theme, Banner's accessibility label and largest size, and TextInput's accessibility label.
[Automated review]
| isLoading: Bool = false, | ||
| isDisabled: Bool = false, | ||
| fillsWidth: Bool = false, | ||
| action: @escaping () -> Void |
There was a problem hiding this comment.
Core's Button contract calls this onClick (ButtonProps.onClick in apple/Sources/AstryxNative/Generated/Button.swift), and AST-093 FR5 asks native components for parameters named and typed as their generated contract. Taking ButtonProps, or recording the accepted interim exemption in AST-093 FR5, resolves it.
| } | ||
|
|
||
| /// What assistive technology reads after the label while loading. | ||
| var loadingValue: String? { isLoading ? "Loading" : nil } |
There was a problem hiding this comment.
This value and the announcement on line 99 are English literals, while core's Button speaks t('@astryx.button.loading'), so a VoiceOver user on a non-English device hears English. A localized string table seeded from core's catalog would keep the word per locale.
|
/approve-spec 710e997 |
Drops the AstryxTemplates library product. The target and its tests stay so templates still compile and are tested; the READMEs describe templates as source to copy into an app, as catalog templates are.
Core's FieldLabel draws the label at the label size and medium weight in color-text-secondary; AstryxTextInput drew it in the primary color.
- templates/ becomes a separate Swift package with no products that depends on the components by path, so the components' Package.swift no longer names template paths. - package.json leaves swift-ios-1/templates out of the npm package; npm pack lists no template file. - Template tests move to templates/Tests.
…ronment, tests - AstryxButton: a loading button stays enabled and undimmed, keeps its width with the spinner drawn over the label, ignores presses, and says Loading to assistive technology, as core's Button does. - Fonts come from the theme's font-family stacks (the generator now keeps them): the first installed family wins, system families use the system font. Headings read font-family-heading. - Banner icons use core's shared icon names, drawn as SF Symbols that a theme can replace; they grow with Dynamic Type. - Without astryxTheme(_:), components follow Dark Mode and Dynamic Type. - Tests for Button (loading, disabled, tap area, largest text), Heading, TextInput, Banner, fonts, and the default environment.
…ibility tests - generate:swift-ios also writes Localizable.strings per locale from core's locale catalogs; AstryxButton's loading value and announcement read @astryx.button.loading from them. A test fails when they drift. - Banner reads its title then its description as one label; TextInput names the field by its label. - Tests: Heading at the largest text size and under a second theme, Banner label and largest size, TextInput label, localized Loading.
Localizations are named by language alone unless a language has several catalogs (pt-BR, pt-PT), with zh-Hans, zh-Hant and nb as Apple spells them. The strings test finds a localization case-insensitively, since SwiftPM may change a folder's case.
…l and trait tests - The README names the three parameters that differ from core's names (action, a Binding for value, an optional level) as the interim shape. - Button exposes its accessible name and button trait, Heading its header trait, and tests assert them.
…ut claiming an exemption
Content is wrapped in a VStack (leading, no added spacing), as children flow inside core's Card. A two-child test checks both children share one card, top to bottom; the test pixel reader now reads rows top first.
New iOS-only tests host each component in a UIHostingController and read the accessibility elements SwiftUI exposes to UIKit: Heading's header trait, the text field's name, and Button's label, button trait, and Loading value. Removing any of those modifiers fails them.
Hosting a SwiftUI view in a UIHostingController stops the hostless SwiftPM test process on the iOS Simulator, failing every main-actor test after it. Reading the accessibility tree needs an app-hosted test target.
…oduct swift-ios-1/ is retired. apple/Package.swift now has two products: Astryx (views, theme, localized messages; Sources/Astryx/<Name>/, tests in Tests/AstryxTests/) and AstryxNative (generated contracts and the logic host). Page templates move to apple/Templates/, still a separate package with no products, and npm files leave apple/Templates out. The theme and strings generators write into Sources/Astryx/.
1d7d9c3 to
c246588
Compare
|
/approve-spec c246588 |
There was a problem hiding this comment.
Changes are needed before this can be approved: the SwiftUI views now live in apple/Sources/Astryx/, but AST-093 on main still places Swift components in swift-ios-<n>/core/ and ties the interim parameter exemption to swift-ios-1, and the evidence AST-093 FR5 asks for is still incomplete.
- Record the
apple/layout in AST-093 FR1 and its Current-state impact onmainand update thepackages/native/specs/guidance, or keep the views inswift-ios-1/core/. - Attach iOS Simulator or device captures of each view's states and of the login template's rest, error and loading states, in light, dark and at the largest text size.
- Make the accessibility assertions observe the rendered views, for example from an app-hosted test target, so that removing
.accessibilityHeading, the field's.accessibilityLabelor the button's Loading.accessibilityValuefails a test. - Resolve
AstryxButton'siconthrough the theme's shared icon names, asAstryxBannerdoes, and list all six parameter differences in the README.
[Automated review]
| └── Tests/ | ||
| ``` | ||
|
|
||
| - **`Sources/Astryx/<Name>/`** holds one folder per component, named as in |
There was a problem hiding this comment.
AST-093 FR1 on main still puts a Swift component's folder and spec at packages/native/swift-ios-<n>/core/<Name>/<Name>.spec.md, and its Current-state impact ties the FR5 parameter exemption to views in swift-ios-1; packages/native/specs/README.md, TEMPLATE.md and the two specs/swift/ READMEs say the same. Recording this Sources/Astryx/<Name>/ layout there keeps the next component spec beside its views.
| - **`Sources/Astryx/<Name>/`** holds one folder per component, named as in | ||
| `packages/core/src/<Name>/`. A component's parameters use core's prop names | ||
| and values (`variant: .primary`, `size: .lg`, `isLoading`), so code reads | ||
| the same across web and native, with three exceptions, the interim shape |
There was a problem hiding this comment.
Besides these three, AstryxButton adds fillsWidth and takes icon as an SF Symbol name (neither is in the generated ButtonProps), and AstryxCard(padding: Int) cannot spell CardPadding's 0.5 and 1.5 steps. Listing them keeps this sentence true for anyone porting web code.
| // spinner draws over it. | ||
| HStack(spacing: astryx.space(2)) { | ||
| if let icon { | ||
| Image(systemName: icon) |
There was a problem hiding this comment.
Image(systemName: icon) takes a raw SF Symbol name, so a shared icon name such as "success" draws nothing and a theme's icons never reach a button (AST-093 FR4; AST-082 FR4 and FR17). Resolving it through astryx.icon(_:), as AstryxBanner does, keeps the shared names and theme replacement.
…all six parameter differences - AstryxButton resolves icon through the theme's shared icon names, as AstryxBanner does. The default map covers every built-in name, and a vitest check keeps it equal to NATIVE_ICON_DEFAULTS. - The README names all six differences from core's parameters.
|
/approve-spec bf745f3 |
There was a problem hiding this comment.
Changes are needed before this can be approved: the SwiftUI views now live in apple/Sources/Astryx/, but AST-093 on main still places Swift component folders in swift-ios-<n>/core/ and ties the interim parameter exemption to swift-ios-1, and the evidence AST-093 FR5 asks for is still incomplete.
- Land the AST-093 amendment for the
apple/layout (#8245) onmain, point thepackages/native/specs/guidance atapple/Sources/Astryx/<Name>/, and giveAstryxHeadingits ownHeading/folder. - Attach iOS Simulator or device captures of each view's states and of the login template's rest, error and loading states, in light, dark and at the largest text size.
- Make the accessibility assertions observe the rendered views, for example from an app-hosted test target, so that removing a label, trait or value modifier fails a test.
[Automated review]
| `packages/core/src/<Name>/`. A component's parameters use core's prop names | ||
| and values (`variant: .primary`, `size: .lg`, `isLoading`), so code reads | ||
| the same across web and native, with six exceptions, the interim shape | ||
| AST-093 FR5 exempts until the components move onto the generated contracts: |
There was a problem hiding this comment.
AST-093's exemption on main covers "The first Swift views in swift-ios-1", and FR1 still puts Swift component folders in packages/native/swift-ios-<n>/core/<Name>/. Until the amendment in #8245 lands, this citation does not cover views in apple/Sources/Astryx/, and packages/native/specs/README.md, specs/TEMPLATE.md, specs/swift/README.md and specs/swift/library/README.md still send component specs to swift-ios-1/core/.
| │ │ │ └── Generated/ # core's default theme, generated; do not edit | ||
| │ │ ├── Resources/ # core's messages per locale, generated; do not edit | ||
| │ │ ├── Localization/ | ||
| │ │ ├── Text/ # AstryxText, AstryxHeading |
There was a problem hiding this comment.
AstryxHeading lives in Text/, but core keeps Heading in its own packages/core/src/Heading/, and AST-093 FR1 gives each native component its own folder named as the core component, so a Heading spec would have no views beside it. Moving it to Sources/Astryx/Heading/ fixes that.
|
|
||
| @MainActor | ||
| @Test func aHeadingIsAHeader() { | ||
| #expect(AstryxHeading.accessibilityTraits.contains(.isHeader)) |
There was a problem hiding this comment.
This reads the static AstryxHeading.accessibilityTraits declared at AstryxText.swift:113, so it stays green if .accessibilityAddTraits and .accessibilityHeading at AstryxText.swift:108-109 are deleted. AST-093 FR5's trait assertion needs to observe the hosted view, for example from an app-hosted test target.
| @MainActor | ||
| @Test func aTextFieldIsNamedByItsLabel() { | ||
| let field = AstryxTextInput(label: "Email", value: .constant("")) | ||
| #expect(field.accessibilityText == "Email") |
There was a problem hiding this comment.
accessibilityText is label (AstryxTextInput.swift:61), so this passes without .accessibilityLabel at AstryxTextInput.swift:55, which is the field's only name because the visible label is hidden from VoiceOver at :43.
| let loading = AstryxButton(label: "Save", isLoading: true) { presses += 1 } | ||
| loading.activate() | ||
| #expect(presses == 0) | ||
| #expect(loading.loadingValue == "Loading") |
There was a problem hiding this comment.
loadingValue is computed beside the view; VoiceOver hears it only through .accessibilityValue at AstryxButton.swift:99, which this assertion never reaches.
As in core, Heading lives in apple/Sources/Astryx/Heading/. Its tests move to HeadingTests.swift, and the text field's to TextInputTests.swift.
|
/approve-spec f4faca3 |
There was a problem hiding this comment.
Approval is waiting on an engineering owner: the SwiftUI views now live in packages/native/apple/Sources/Astryx/, but AST-093 on main still places Swift component folders in swift-ios-<n>/core/ (FR1) and grants the interim parameter exemption to views in swift-ios-1 (Current-state impact). An engineering owner needs to update those AST-093 claims on main for the apple/ layout (the open amendment, #8245) and record the decision by commenting /approve-spec <full head SHA> on this pull request; the author may do both as an engineering owner. Whatever that decision, these still need changes:
- Attach iOS Simulator or device captures of each view's states and of the login template's rest, error and loading states, in light, dark and at the largest text size (AST-093 FR5).
- Make the accessibility assertions observe the rendered views, for example from an app-hosted test target, so that removing a label, trait or value modifier fails a test.
- If the
apple/layout stays, point thepackages/native/specs/guidance atapple/Sources/Astryx/<Name>/.
[Automated review]
|
|
||
| @MainActor | ||
| @Test func aHeadingIsAHeader() { | ||
| #expect(AstryxHeading.accessibilityTraits.contains(.isHeader)) |
There was a problem hiding this comment.
This reads the static AstryxHeading.accessibilityTraits, not what the rendered heading exposes, so deleting .accessibilityAddTraits and .accessibilityHeading in AstryxHeading.swift (lines 29-30) leaves it green. AST-093 FR5 asks for accessibility assertions, and they need to fail when the trait is removed; a test that reads the heading's accessibility element from an app-hosted target would.
| #expect(AstryxButton(label: "Save") {}.accessibilityText == "Save") | ||
| #expect(AstryxButton(label: "Save", isLoading: true) {}.accessibilityText == "Save") | ||
| #expect(AstryxButton.accessibilityTraits.contains(.isButton)) |
There was a problem hiding this comment.
These compare accessibilityText and the static accessibilityTraits with the values they are declared as; VoiceOver hears them only through the modifiers at AstryxButton.swift:97-99, which no test reads. The same applies to loadingValue at line 16.
| the same across web and native, with six exceptions, the interim shape | ||
| AST-093 FR5 exempts until the components move onto the generated contracts: |
There was a problem hiding this comment.
On main, AST-093's Current-state impact grants this exemption to the views “in swift-ios-1”; it covers Sources/Astryx/ once the AST-093 amendment for the apple/ layout lands.
User need
A team building an iOS app with Astryx has nothing to start from: the web components do not run on iOS, and the native package has generated props types but no views. People trying Astryx in SwiftUI also need one agreed place for components and templates, so work from different people lands in the same shape instead of in separate forks.
Problem and solution fit
packages/native/apple/is a Swift package. The1is a generation, not an iOS version, so a rethink can startswift-ios-2beside it and both can be scored before one is retired.core/for components. One folder per component, named as inpackages/core/src/<Name>/: Text and Heading, Button, TextInput, Card, Banner. Parameters use core's prop names and values (variant: .primary,size: .lg,isLoading).templates/for templates. One folder perastryx templateid, built only fromcore/and SwiftUI layout. It starts withlogin, which matches the web template's content, validation message, and loading state.core/Theme/Generated/DefaultTheme.swiftis core's default theme run through core's own resolver, light and dark (pnpm -F @astryxdesign/native generate:swift-ios). A test fails when it drifts. Components read every color, size, and font from the theme, and text grows with Dynamic Type.apple/README.mdcovers the layout, how to use it, the token rules, how to add a component or template, and what is not done yet.Current specification
AST-082 (
current): DEC-7 (native implementations live in@astryxdesign/native), FR11 (native-first on each platform), FR12 arm A (platform views painted with Astryx's tokens).Public delta and caller burden
@astryxdesign/native(private, canary-only) addsapple/(theAstryxproduct) to its files, minusapple/Templates, and agenerate:swift-iosscript.Astryx(components). Page templates are clone-only:templates/is its own Swift package with no products, depending on the components by path, and it is left out of the npm package (npm pack --dry-runlists no template file). An app copies a template's folder:Design and alternatives
apple/(ButtonPropsand so on) once those contracts exist, so a core prop change reaches Swift.Evidence
pnpm vitest run --project node packages/native: 33 tests pass, including color keywords, the theme drift check, andcolor-tint-hover.pnpm -F @astryxdesign/native typecheckpasses; the commit hook's repo checks pass.core/andtemplates/compile as modules; both test targets typecheck against them.ImageRendereron macOS in light and dark: buttons in every variant and size, error and success banners, a card, and the login column in its rest and error states. Text fields draw as blank boxes in an image render, which is a renderer limit.test-native-swiftinci.yml(joined bytest, merged in ci(native): build and test the native Swift packages on macOS #7984) runs on macOS for everyPackage.swiftunderpackages/nativewhen Swift changes:swift testfor a package that supports macOS and has test targets, then an iOS Simulator build. This package is in that tree, so this PR's own run builds and tests it; no separate lane is added here..xsm(tokenfont-size-xs), as core's Text; the button's tap area is at least 44 × 44 pt; the theme generator readsblack/white(socolor-tint-hoveris present) and fails on any unreadable kept token;generate:swift-iosbuilds core first. New SwiftTextTestsand node assertions cover them.font-family-*stacks (first installed family, system font for system families) and headings read the heading family; Banner icons use core's shared icon names (info,warning,error,success) as SF Symbols a theme can replace, sized to grow with Dynamic Type; withoutastryxTheme(_:)components follow Dark Mode and Dynamic Type.ImageRendererrenders on macOS of the components in light, dark (without the theme modifier), and the largest accessibility text size. They are not simulator captures, andImageRendererdraws the text field and spinner as placeholders.@astryx.button.loadingfromLocalizable.stringsgenerated per locale from core's catalogs (a vitest drift test; a Swift test checks en and de-DE)..accessibilityAddTraits(.isHeader), the field's.accessibilityLabel, or the button's Loading.accessibilityValueis removed. The checks above test the values and traits each view applies, not the rendered tree.swift teston macOS and an iOS Simulator build; simulator test runs arrive with the CI change that adds them) and on-device pixels.Scope
Testing