An open source design system that's fully customizable and agent ready
TypeScript
feat(native): Swift views take core's names in the Astryx module (#8299)
Cindy Zhang577e8caea320
diff --git a/packages/native/apple/README.md b/packages/native/apple/README.mdindex 8ecae2ae85..ce71fc1307 100644--- a/packages/native/apple/README.md+++ b/packages/native/apple/README.md@@ -26,12 +26,12 @@ apple/│ │ │ └── Generated/ # typed tokens and every published theme, generated; do not edit│ │ ├── Resources/ # core's messages per locale, generated; do not edit│ │ ├── Localization/-│ │ ├── Text/ # AstryxText-│ │ ├── Heading/ # AstryxHeading-│ │ ├── Button/ # AstryxButton-│ │ ├── TextInput/ # AstryxTextInput-│ │ ├── Card/ # AstryxCard-│ │ └── Banner/ # AstryxBanner+│ │ ├── Text/ # Text+│ │ ├── Heading/ # Heading+│ │ ├── Button/ # Button+│ │ ├── TextInput/ # TextInput+│ │ ├── Card/ # Card+│ │ └── Banner/ # Banner│ └── AstryxNative/ # contracts, wire, logic host (module AstryxNative)│ └── Generated/ # generated; do not edit├── Tests/@@ -44,17 +44,21 @@ apple/```- **`Sources/Astryx/<Name>/`** holds one folder per component, named as in- `packages/core/src/<Name>/`. A component's parameters use core's prop names+ `packages/core/src/<Name>/`. Each view has core's component name in the+ `Astryx` module (`Button`, `Text`), which re-exports SwiftUI and the+ generated contracts, so an app file writes `import Astryx` alone. In a file+ that also imports SwiftUI, write `Astryx.Button` and `SwiftUI.Button`. A+ component's parameters use core's prop namesand values (`variant: .primary`, `size: .lg`, `isLoading`), so code readsthe same across web and native, with six exceptions, the interim shapeAST-093 FR5 exempts until the components move onto the generated contracts:- - `AstryxButton` takes `action` where core has `onClick`.- - `AstryxButton` takes `fillsWidth` where core has `width="100%"`.- - `AstryxButton` takes `icon` as a shared icon name (`"search"`), which the+ - `Button` takes `action` where core has `onClick`.+ - `Button` takes `fillsWidth` where core has `width="100%"`.+ - `Button` takes `icon` as a shared icon name (`"search"`), which thegenerated `ButtonProps` does not carry yet.- - `AstryxTextInput` takes a `Binding` where core has `value` and `onChange`.- - `AstryxHeading`'s `level` is optional where core requires it.- - `AstryxCard` takes `padding` as a whole spacing step, so it cannot spell+ - `TextInput` takes a `Binding` where core has `value` and `onChange`.+ - `Heading`'s `level` is optional where core requires it.+ - `Card` takes `padding` as a whole spacing step, so it cannot spellcore's `0.5` and `1.5` steps.- **`Templates/`** holds one folder per page template, named after the`astryx template` id. Templates are clone-only, as on the web: you copy a@@ -74,7 +78,6 @@ app.```swiftimport Astryx-import SwiftUI@mainstruct DemoApp: App {@@ -173,8 +176,9 @@ Both packages also declare macOS 14 so they build and test on a Mac without asimulator; iOS 17 is the target. Open `Templates/Package.swift` in Xcode torun `LoginTemplate` in an iOS simulator through its preview.-To add a component, create `Sources/Astryx/<Name>/Astryx<Name>.swift` with-core's prop names, read its tokens from `astryx`, and add tests under+To add a component, create `Sources/Astryx/<Name>/<Name>.swift` declaring+`<Name>` with core's prop names, writing `SwiftUI.<Name>` wherever it means the+system type, read its tokens from `astryx`, and add tests under`Tests/AstryxTests/`. To add a template, create`Templates/<Name>/<Name>Template.swift` from the output of`astryx template <id>`, with tests under `Templates/Tests/`.diff --git a/packages/native/apple/Sources/Astryx/Banner/AstryxBanner.swift b/packages/native/apple/Sources/Astryx/Banner/Banner.swiftsimilarity index 92%rename from packages/native/apple/Sources/Astryx/Banner/AstryxBanner.swiftrename to packages/native/apple/Sources/Astryx/Banner/Banner.swiftindex 8760f74a5d..2c5d00388e 100644--- a/packages/native/apple/Sources/Astryx/Banner/AstryxBanner.swift+++ b/packages/native/apple/Sources/Astryx/Banner/Banner.swift@@ -35,7 +35,7 @@ public enum AstryxBannerStatus: String, CaseIterable, Sendable {/// A message about the page or a section of it. The status sets the color/// and icon only; the title must say what happened, because the icon is/// decorative to VoiceOver.-public struct AstryxBanner: View {+public struct Banner: View {let status: AstryxBannerStatuslet title: Stringlet description: String?@@ -57,9 +57,9 @@ public struct AstryxBanner: View {.accessibilityHidden(true)}VStack(alignment: .leading, spacing: astryx.space(1)) {- AstryxText(title, weight: .semibold)+ Text(title, weight: .semibold)if let description {- AstryxText(description, color: .secondary)+ Text(description, color: .secondary)}}.frame(maxWidth: .infinity, alignment: .leading)@@ -70,7 +70,7 @@ public struct AstryxBanner: View {.fill(astryx.color(status.groundToken))).accessibilityElement(children: .ignore)- .accessibilityLabel(Text(accessibilityText))+ .accessibilityLabel(SwiftUI.Text(accessibilityText))}/// What VoiceOver reads: the title, then the description.diff --git a/packages/native/apple/Sources/Astryx/Button/AstryxButton.swift b/packages/native/apple/Sources/Astryx/Button/Button.swiftsimilarity index 95%rename from packages/native/apple/Sources/Astryx/Button/AstryxButton.swiftrename to packages/native/apple/Sources/Astryx/Button/Button.swiftindex e638a68e02..938ec00954 100644--- a/packages/native/apple/Sources/Astryx/Button/AstryxButton.swift+++ b/packages/native/apple/Sources/Astryx/Button/Button.swift@@ -29,7 +29,7 @@ public enum AstryxButtonSize: String, CaseIterable, Sendable {/// A labeled action, painted with the theme's tokens. The tap area reaches/// the platform's 44-by-44-point minimum even when the drawn button is smaller.-public struct AstryxButton: View {+public struct Button: View {let label: Stringlet variant: AstryxButtonVariantlet size: AstryxButtonSize@@ -66,14 +66,14 @@ public struct AstryxButton: View {}public var body: some View {- Button(action: activate) {+ SwiftUI.Button(action: activate) {// The label keeps its place while loading so the width holds; the// spinner draws over it.HStack(spacing: astryx.space(2)) {if let icon, let symbol = astryx.icon(icon) {Image(systemName: symbol)}- Text(label).lineLimit(1)+ SwiftUI.Text(label).lineLimit(1)}.opacity(isLoading ? 0 : 1).overlay {@@ -94,9 +94,9 @@ public struct AstryxButton: View {// As core's Button: a loading button stays undimmed and focusable, keeps// its label, and says Loading; taps do nothing until it finishes..disabled(isDisabled)- .accessibilityLabel(Text(accessibilityText))+ .accessibilityLabel(SwiftUI.Text(accessibilityText)).accessibilityAddTraits(Self.accessibilityTraits)- .accessibilityValue(Text(loadingValue ?? ""))+ .accessibilityValue(SwiftUI.Text(loadingValue ?? "")).onChange(of: isLoading) { _, loading inif loading { AccessibilityNotification.Announcement(AstryxStrings.buttonLoading).post() }}diff --git a/packages/native/apple/Sources/Astryx/Card/AstryxCard.swift b/packages/native/apple/Sources/Astryx/Card/Card.swiftsimilarity index 95%rename from packages/native/apple/Sources/Astryx/Card/AstryxCard.swiftrename to packages/native/apple/Sources/Astryx/Card/Card.swiftindex 1fd20f8f69..c27dfc5704 100644--- a/packages/native/apple/Sources/Astryx/Card/AstryxCard.swift+++ b/packages/native/apple/Sources/Astryx/Card/Card.swift@@ -4,7 +4,7 @@ import SwiftUI/// A card: one independent item on the theme's card ground, with a hairline/// border and the container radius.-public struct AstryxCard<Content: View>: View {+public struct Card<Content: View>: View {let padding: Intlet content: Content@Environment(\.astryx) private var astryxdiff --git a/packages/native/apple/Sources/Astryx/Exports.swift b/packages/native/apple/Sources/Astryx/Exports.swiftnew file mode 100644index 0000000000..56baaddb5a--- /dev/null+++ b/packages/native/apple/Sources/Astryx/Exports.swift@@ -0,0 +1,8 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++// `import Astryx` is the only import an app file needs: it brings SwiftUI and+// the generated contracts with it. In a file that imports only Astryx, a name+// Astryx shares with SwiftUI (`Button`, `Text`) means Astryx's view, and+// `SwiftUI.Button` names the system one (Swift component API spec, A1, A1a).+@_exported import AstryxNative+@_exported import SwiftUIdiff --git a/packages/native/apple/Sources/Astryx/Heading/AstryxHeading.swift b/packages/native/apple/Sources/Astryx/Heading/Heading.swiftsimilarity index 95%rename from packages/native/apple/Sources/Astryx/Heading/AstryxHeading.swiftrename to packages/native/apple/Sources/Astryx/Heading/Heading.swiftindex 51aed9c17a..ac2a708410 100644--- a/packages/native/apple/Sources/Astryx/Heading/AstryxHeading.swift+++ b/packages/native/apple/Sources/Astryx/Heading/Heading.swift@@ -5,7 +5,7 @@ import SwiftUI/// A heading at levels 1 through 6, painted with the theme's heading tokens/// and exposed to VoiceOver as a heading.-public struct AstryxHeading: View {+public struct Heading: View {let content: Stringlet level: Int@Environment(\.astryx) private var astryx@@ -16,7 +16,7 @@ public struct AstryxHeading: View {}public var body: some View {- Text(content)+ SwiftUI.Text(content).font(astryx.font(size: "text-heading-\(level)-size",diff --git a/packages/native/apple/Sources/Astryx/Text/AstryxText.swift b/packages/native/apple/Sources/Astryx/Text/Text.swiftsimilarity index 97%rename from packages/native/apple/Sources/Astryx/Text/AstryxText.swiftrename to packages/native/apple/Sources/Astryx/Text/Text.swiftindex 14da07455f..c4c85bc3a9 100644--- a/packages/native/apple/Sources/Astryx/Text/AstryxText.swift+++ b/packages/native/apple/Sources/Astryx/Text/Text.swift@@ -51,7 +51,7 @@ public enum AstryxTextSize: String, CaseIterable, Sendable {}/// A run of text in a semantic type, painted with the theme's type tokens.-public struct AstryxText: View {+public struct Text: View {let content: Stringlet type: AstryxTextTypelet color: AstryxTextColor?@@ -76,7 +76,7 @@ public struct AstryxText: View {public var body: some View {let sizeToken = size?.token ?? "\(type.token)-size"let weightToken = weight?.token ?? "\(type.token)-weight"- Text(content)+ SwiftUI.Text(content).font(astryx.font(size: sizeToken, 14, weight: weightToken)).foregroundStyle(astryx.color((color ?? type.defaultColor).token))}diff --git a/packages/native/apple/Sources/Astryx/TextInput/AstryxTextInput.swift b/packages/native/apple/Sources/Astryx/TextInput/TextInput.swiftsimilarity index 90%rename from packages/native/apple/Sources/Astryx/TextInput/AstryxTextInput.swiftrename to packages/native/apple/Sources/Astryx/TextInput/TextInput.swiftindex 67e8bb9d2c..bccb5ab0f7 100644--- a/packages/native/apple/Sources/Astryx/TextInput/AstryxTextInput.swift+++ b/packages/native/apple/Sources/Astryx/TextInput/TextInput.swift@@ -12,7 +12,7 @@ public enum AstryxTextInputType: String, CaseIterable, Sendable {/// A labeled one-line text field, painted with the theme's tokens. The label/// stays visible above the field and is the field's accessibility label.-public struct AstryxTextInput: View {+public struct TextInput: View {let label: String@Binding var value: Stringlet type: AstryxTextInputType@@ -39,7 +39,7 @@ public struct AstryxTextInput: View {public var body: some View {VStack(alignment: .leading, spacing: astryx.space(1)) {- AstryxText(label, type: .label, color: .secondary)+ Text(label, type: .label, color: .secondary).accessibilityHidden(true)field.font(astryx.font(size: "text-body-size", 14, weight: "text-body-weight"))@@ -52,7 +52,7 @@ public struct AstryxTextInput: View {).disabled(isDisabled).opacity(isDisabled ? 0.5 : 1)- .accessibilityLabel(Text(accessibilityText))+ .accessibilityLabel(SwiftUI.Text(accessibilityText))}}@@ -61,7 +61,7 @@ public struct AstryxTextInput: View {var accessibilityText: String { label }@ViewBuilder private var field: some View {- let prompt = placeholder.map { Text($0).foregroundStyle(astryx.color("color-text-secondary")) }+ let prompt = placeholder.map { SwiftUI.Text($0).foregroundStyle(astryx.color("color-text-secondary")) }switch type {case .password:SecureField("", text: $value, prompt: prompt)diff --git a/packages/native/apple/Templates/Login/LoginTemplate.swift b/packages/native/apple/Templates/Login/LoginTemplate.swiftindex cb1fc206f9..4bd25fc882 100644--- a/packages/native/apple/Templates/Login/LoginTemplate.swift+++ b/packages/native/apple/Templates/Login/LoginTemplate.swift@@ -1,7 +1,6 @@// Copyright (c) Meta Platforms, Inc. and affiliates.import Astryx-import SwiftUI/// The `login` template's state and rules, kept apart from the drawing so/// they can be tested without a screen.@@ -66,36 +65,36 @@ struct LoginTemplateContent: View {.font(.system(size: astryx.fontSize("font-size-2xl", 24))).foregroundStyle(astryx.color("color-icon-primary")).accessibilityHidden(true)- AstryxText("Product Inc.", size: .lg, weight: .bold)+ Text("Product Inc.", size: .lg, weight: .bold)}- AstryxCard(padding: 8) {+ Card(padding: 8) {VStack(alignment: .leading, spacing: astryx.space(4)) {VStack(spacing: astryx.space(1)) {- AstryxHeading("Sign in", level: 2)- AstryxText("Enter your credentials to continue", color: .secondary, size: .sm)+ Heading("Sign in", level: 2)+ Text("Enter your credentials to continue", color: .secondary, size: .sm)}.frame(maxWidth: .infinity)if let error = form.error {- AstryxBanner(status: .error, title: error)+ Banner(status: .error, title: error)}- AstryxTextInput(+ TextInput(label: "Email",value: $form.email,type: .email,size: .lg,placeholder: "[email protected]")- AstryxTextInput(+ TextInput(label: "Password",value: $form.password,type: .password,size: .lg,placeholder: "Enter your password")- AstryxButton(+ Button(label: "Sign in",variant: .primary,size: .lg,diff --git a/packages/native/apple/Tests/AstryxTests/BannerTests.swift b/packages/native/apple/Tests/AstryxTests/BannerTests.swiftindex babf7fc184..cc36899e7b 100644--- a/packages/native/apple/Tests/AstryxTests/BannerTests.swift+++ b/packages/native/apple/Tests/AstryxTests/BannerTests.swift@@ -24,23 +24,23 @@ import Testing@Test func aBannerPaintsItsStatusGround() {var theme = Theme.defaulttheme.light.color.successMuted = Color(astryxRGBA: 0xFDE68AFF)- let banner = AstryxBanner(status: .success, title: "Saved").frame(width: 240)+ let banner = Astryx.Banner(status: .success, title: "Saved").frame(width: 240)let pixels = Pixels(banner, theme: theme)#expect(close(pixels.at(pixels.width - 6, pixels.height / 2), rgba("#FDE68AFF")))}@MainActor@Test func aBannerReadsItsTitleThenItsDescription() {- #expect(AstryxBanner(status: .error, title: "Upload failed").accessibilityText == "Upload failed")+ #expect(Astryx.Banner(status: .error, title: "Upload failed").accessibilityText == "Upload failed")#expect(- AstryxBanner(status: .error, title: "Upload failed", description: "Try again.").accessibilityText+ Astryx.Banner(status: .error, title: "Upload failed", description: "Try again.").accessibilityText== "Upload failed, Try again.")}@MainActor@Test func aBannerGrowsAtTheLargestTextSize() {- let banner = AstryxBanner(status: .info, title: "Heads up", description: "Details.").frame(width: 320)+ let banner = Astryx.Banner(status: .info, title: "Heads up", description: "Details.").frame(width: 320)let large = Pixels(banner)let largest = Pixels(banner, typeSize: .accessibility5)#expect(largest.height > large.height * 2)diff --git a/packages/native/apple/Tests/AstryxTests/ButtonTests.swift b/packages/native/apple/Tests/AstryxTests/ButtonTests.swiftindex dba9c4435e..8e1b5633ff 100644--- a/packages/native/apple/Tests/AstryxTests/ButtonTests.swift+++ b/packages/native/apple/Tests/AstryxTests/ButtonTests.swift@@ -10,12 +10,12 @@ import Testing@MainActor@Test func aLoadingButtonIgnoresPressesAndSaysLoading() {var presses = 0- let loading = AstryxButton(label: "Save", isLoading: true) { presses += 1 }+ let loading = Astryx.Button(label: "Save", isLoading: true) { presses += 1 }loading.activate()#expect(presses == 0)#expect(loading.loadingValue == "Loading")- let ready = AstryxButton(label: "Save") { presses += 1 }+ let ready = Astryx.Button(label: "Save") { presses += 1 }ready.activate()#expect(presses == 1)#expect(ready.loadingValue == nil)@@ -24,8 +24,8 @@ import Testing@MainActor@Test func aLoadingButtonIsNotDimmedAndKeepsItsWidth() {let accent = rgba(Theme.default.light.color.accent)- let loading = Pixels(AstryxButton(label: "Continue", variant: .primary, isLoading: true) {}.fixedSize())- let ready = Pixels(AstryxButton(label: "Continue", variant: .primary) {}.fixedSize())+ let loading = Pixels(Astryx.Button(label: "Continue", variant: .primary, isLoading: true) {}.fixedSize())+ let ready = Pixels(Astryx.Button(label: "Continue", variant: .primary) {}.fixedSize())#expect(close(loading.at(8, loading.height / 2), accent))#expect(loading.width == ready.width)}@@ -33,30 +33,30 @@ import Testing@MainActor@Test func aDisabledButtonIsDimmed() {let accent = rgba(Theme.default.light.color.accent)- let disabled = Pixels(AstryxButton(label: "Continue", variant: .primary, isDisabled: true) {}.fixedSize())+ let disabled = Pixels(Astryx.Button(label: "Continue", variant: .primary, isDisabled: true) {}.fixedSize())#expect(!close(disabled.at(8, disabled.height / 2), accent))}@MainActor@Test func theTapAreaIsAtLeast44PointsEvenForSmallButtons() {- let small = Pixels(AstryxButton(label: "OK", size: .sm) {}.fixedSize())+ let small = Pixels(Astryx.Button(label: "OK", size: .sm) {}.fixedSize())#expect(small.width >= 44)#expect(small.height >= 44)}@MainActor@Test func buttonLabelsGrowAtTheLargestTextSizeWithoutClipping() {- let large = Pixels(AstryxButton(label: "Continue") {}.fixedSize())- let largest = Pixels(AstryxButton(label: "Continue") {}.fixedSize(), typeSize: .accessibility5)+ let large = Pixels(Astryx.Button(label: "Continue") {}.fixedSize())+ let largest = Pixels(Astryx.Button(label: "Continue") {}.fixedSize(), typeSize: .accessibility5)#expect(largest.width > large.width)#expect(largest.height > large.height)}@MainActor@Test func aButtonIsNamedByItsLabelAndIsAButton() {- #expect(AstryxButton(label: "Save") {}.accessibilityText == "Save")- #expect(AstryxButton(label: "Save", isLoading: true) {}.accessibilityText == "Save")- #expect(AstryxButton.accessibilityTraits.contains(.isButton))+ #expect(Astryx.Button(label: "Save") {}.accessibilityText == "Save")+ #expect(Astryx.Button(label: "Save", isLoading: true) {}.accessibilityText == "Save")+ #expect(Astryx.Button.accessibilityTraits.contains(.isButton))}@Test func buttonIconsUseSharedNamesAndTheTheme() {@@ -66,7 +66,7 @@ import Testing@MainActor@Test func aButtonDrawsItsSharedIcon() {- let plain = Pixels(AstryxButton(label: "Find") {}.fixedSize())- let withIcon = Pixels(AstryxButton(label: "Find", icon: "search") {}.fixedSize())+ let plain = Pixels(Astryx.Button(label: "Find") {}.fixedSize())+ let withIcon = Pixels(Astryx.Button(label: "Find", icon: "search") {}.fixedSize())#expect(withIcon.width > plain.width)}diff --git a/packages/native/apple/Tests/AstryxTests/CardTests.swift b/packages/native/apple/Tests/AstryxTests/CardTests.swiftindex 83e3ed3d18..84f0c08164 100644--- a/packages/native/apple/Tests/AstryxTests/CardTests.swift+++ b/packages/native/apple/Tests/AstryxTests/CardTests.swift@@ -6,7 +6,7 @@ import Testing@MainActor@Test func severalChildrenStackInOneCard() {- let card = AstryxCard(padding: 0) {+ let card = Astryx.Card(padding: 0) {Color(astryxHex: "#FF0000FF").frame(width: 80, height: 40)Color(astryxHex: "#0000FFFF").frame(width: 80, height: 40)}diff --git a/packages/native/apple/Tests/AstryxTests/EnvironmentTests.swift b/packages/native/apple/Tests/AstryxTests/EnvironmentTests.swiftindex 116e46c6fb..f21b79b8a5 100644--- a/packages/native/apple/Tests/AstryxTests/EnvironmentTests.swift+++ b/packages/native/apple/Tests/AstryxTests/EnvironmentTests.swift@@ -9,7 +9,7 @@ import Testing@MainActor@Test func withoutAThemeComponentsFollowDarkMode() {- let card = AstryxCard { Color.clear.frame(width: 80, height: 40) }.frame(width: 120)+ let card = Astryx.Card { Color.clear.frame(width: 80, height: 40) }.frame(width: 120)let light = Pixels(card, scheme: .light)let dark = Pixels(card, scheme: .dark)#expect(close(light.at(60, light.height / 2), rgba(Theme.default.light.color.backgroundCard)))@@ -18,8 +18,8 @@ import Testing@MainActor@Test func withoutAThemeTextFollowsDynamicType() {- let large = Pixels(AstryxText("Hello").fixedSize())- let larger = Pixels(AstryxText("Hello").fixedSize(), typeSize: .xxxLarge)+ let large = Pixels(Astryx.Text("Hello").fixedSize())+ let larger = Pixels(Astryx.Text("Hello").fixedSize(), typeSize: .xxxLarge)#expect(larger.width > large.width)}diff --git a/packages/native/apple/Tests/AstryxTests/HeadingTests.swift b/packages/native/apple/Tests/AstryxTests/HeadingTests.swiftindex 845b598175..f5a2a8f1c5 100644--- a/packages/native/apple/Tests/AstryxTests/HeadingTests.swift+++ b/packages/native/apple/Tests/AstryxTests/HeadingTests.swift@@ -6,35 +6,35 @@ import Testing@MainActor@Test func headingLevelsAreClampedAndExposedToVoiceOver() {- #expect(AstryxHeading("Title", level: 0).level == 1)- #expect(AstryxHeading("Title", level: 9).level == 6)- #expect(AstryxHeading("Title", level: 1).headingLevel == .h1)- #expect(AstryxHeading("Title", level: 3).headingLevel == .h3)- #expect(AstryxHeading("Title", level: 6).headingLevel == .h6)+ #expect(Astryx.Heading("Title", level: 0).level == 1)+ #expect(Astryx.Heading("Title", level: 9).level == 6)+ #expect(Astryx.Heading("Title", level: 1).headingLevel == .h1)+ #expect(Astryx.Heading("Title", level: 3).headingLevel == .h3)+ #expect(Astryx.Heading("Title", level: 6).headingLevel == .h6)}@MainActor@Test func headingsShrinkByLevel() {- let h1 = Pixels(AstryxHeading("Settings", level: 1).fixedSize())- let h4 = Pixels(AstryxHeading("Settings", level: 4).fixedSize())+ let h1 = Pixels(Astryx.Heading("Settings", level: 1).fixedSize())+ let h4 = Pixels(Astryx.Heading("Settings", level: 4).fixedSize())#expect(h1.width > h4.width)}@MainActor@Test func headingsGrowAtTheLargestTextSizeAndFollowASecondTheme() {- let large = Pixels(AstryxHeading("Settings").fixedSize())- let largest = Pixels(AstryxHeading("Settings").fixedSize(), typeSize: .accessibility5)+ let large = Pixels(Astryx.Heading("Settings").fixedSize())+ let largest = Pixels(Astryx.Heading("Settings").fixedSize(), typeSize: .accessibility5)#expect(largest.width > large.width * 2)var theme = Theme.defaulttheme.light.font.heading2Size = 48theme.light.color.textPrimary = Color(astryxRGBA: 0xFF0000FF)- let themed = Pixels(AstryxHeading("Settings").fixedSize(), theme: theme)+ let themed = Pixels(Astryx.Heading("Settings").fixedSize(), theme: theme)#expect(themed.width > large.width)#expect(themed.contains { $0[0] > 200 && $0[1] < 60 && $0[2] < 60 && $0[3] > 200 })}@MainActor@Test func aHeadingIsAHeader() {- #expect(AstryxHeading.accessibilityTraits.contains(.isHeader))+ #expect(Astryx.Heading.accessibilityTraits.contains(.isHeader))}diff --git a/packages/native/apple/Tests/AstryxTests/NamesTests.swift b/packages/native/apple/Tests/AstryxTests/NamesTests.swiftnew file mode 100644index 0000000000..1113ecace9--- /dev/null+++ b/packages/native/apple/Tests/AstryxTests/NamesTests.swift@@ -0,0 +1,28 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++import Testing+@testable import Astryx++// Swift component API spec, A1 and A1a. This file imports only Astryx, as an+// app file does: SwiftUI comes with it, a name Astryx shares with SwiftUI+// means Astryx's view, and `SwiftUI.<Name>` names the system one.++@MainActor+@Test func aFileThatImportsOnlyAstryxGetsAstryxViews() {+ let text: Text = Text("Hello")+ let qualified: Astryx.Text = text+ let button: Button = Button(label: "Save") {}+ let card = Card { Text("Inside") }+ let system: SwiftUI.Text = SwiftUI.Text("System")+ let systemButton = SwiftUI.Button("Cancel") {}+ #expect(type(of: qualified) == Astryx.Text.self)+ #expect(type(of: button) == Astryx.Button.self)+ #expect(type(of: card) == Astryx.Card<Astryx.Text>.self)+ #expect(type(of: system) == SwiftUI.Text.self)+ #expect(type(of: systemButton) == SwiftUI.Button<SwiftUI.Text>.self)+}++@Test func theGeneratedContractsComeWithAstryx() {+ let props = ButtonProps(label: "Save", variant: .primary)+ #expect(props.variant == .primary)+}diff --git a/packages/native/apple/Tests/AstryxTests/TextInputTests.swift b/packages/native/apple/Tests/AstryxTests/TextInputTests.swiftindex 45bd2de702..d2236ba629 100644--- a/packages/native/apple/Tests/AstryxTests/TextInputTests.swift+++ b/packages/native/apple/Tests/AstryxTests/TextInputTests.swift@@ -6,7 +6,7 @@ import Testing@MainActor@Test func aTextFieldIsAtLeast44PointsTallAtEveryTextSize() {- let field = AstryxTextInput(label: "Email", value: .constant(""), size: .sm).frame(width: 240)+ let field = Astryx.TextInput(label: "Email", value: .constant(""), size: .sm).frame(width: 240)for typeSize in [DynamicTypeSize.xSmall, .large, .accessibility5] {let pixels = Pixels(field, typeSize: typeSize)// The label sits above a field at least 44 tall.@@ -18,12 +18,12 @@ import Testing@Test func aFieldLabelUsesTheSecondaryTextColor() {var theme = Theme.defaulttheme.light.color.textSecondary = Color(astryxRGBA: 0xFF0000FF)- let pixels = Pixels(AstryxTextInput(label: "Email", value: .constant("")).frame(width: 240), theme: theme)+ let pixels = Pixels(Astryx.TextInput(label: "Email", value: .constant("")).frame(width: 240), theme: theme)#expect(pixels.contains { $0[0] > 200 && $0[1] < 60 && $0[2] < 60 && $0[3] > 200 })}@MainActor@Test func aTextFieldIsNamedByItsLabel() {- let field = AstryxTextInput(label: "Email", value: .constant(""))+ let field = Astryx.TextInput(label: "Email", value: .constant(""))#expect(field.accessibilityText == "Email")}diff --git a/packages/native/apple/Tests/AstryxTests/TextTests.swift b/packages/native/apple/Tests/AstryxTests/TextTests.swiftindex dae80e048f..6a4219c020 100644--- a/packages/native/apple/Tests/AstryxTests/TextTests.swift+++ b/packages/native/apple/Tests/AstryxTests/TextTests.swift@@ -19,7 +19,7 @@ import Testing@MainActor@Test func textGrowsAtTheLargestDynamicTypeSize() {- let large = Pixels(AstryxText("Hello").fixedSize())- let largest = Pixels(AstryxText("Hello").fixedSize(), typeSize: .accessibility5)+ let large = Pixels(Astryx.Text("Hello").fixedSize())+ let largest = Pixels(Astryx.Text("Hello").fixedSize(), typeSize: .accessibility5)#expect(largest.width > large.width * 2)}diff --git a/packages/native/apple/Tests/AstryxTests/TwoThemeTests.swift b/packages/native/apple/Tests/AstryxTests/TwoThemeTests.swiftindex a675c02f9e..0778606e88 100644--- a/packages/native/apple/Tests/AstryxTests/TwoThemeTests.swift+++ b/packages/native/apple/Tests/AstryxTests/TwoThemeTests.swift@@ -28,7 +28,7 @@ private let secondTheme: Theme = {@MainActor@Test func cardFollowsTheThemesGroundAndShape() {- let card = AstryxCard { Color.clear.frame(width: 80, height: 40) }.frame(width: 120)+ let card = Astryx.Card { Color.clear.frame(width: 80, height: 40) }.frame(width: 120)let standard = Pixels(card, theme: .default)let second = Pixels(card, theme: secondTheme)@@ -43,7 +43,7 @@ private let secondTheme: Theme = {@MainActor@Test func buttonFollowsTheThemesAccentTypeAndShape() {- let button = AstryxButton(label: "Continue", variant: .primary) {}.fixedSize()+ let button = Astryx.Button(label: "Continue", variant: .primary) {}.fixedSize()let standard = Pixels(button, theme: .default)let second = Pixels(button, theme: secondTheme)@@ -55,7 +55,7 @@ private let secondTheme: Theme = {@MainActor@Test func textFollowsTheThemesColorAndTypeSize() {- let text = AstryxText("Hello").fixedSize()+ let text = Astryx.Text("Hello").fixedSize()let standard = Pixels(text, theme: .default)let second = Pixels(text, theme: secondTheme)diff --git a/packages/native/specs/README.md b/packages/native/specs/README.mdindex 072ebefc54..69c88cc314 100644--- a/packages/native/specs/README.md+++ b/packages/native/specs/README.md@@ -14,7 +14,7 @@ packages/native/│ └── library/ # rules every Swift component or build step shares└── apple/Sources/Astryx/└── <Name>/ # one folder per component, named as core's- ├── Astryx<Name>.swift+ ├── <Name>.swift # declares <Name> in the Astryx module└── <Name>.spec.md # the component's spec, e.g. Button.spec.md```diff --git a/packages/native/specs/swift/library/component-api.md b/packages/native/specs/swift/library/component-api.mdindex 51c7f51f42..23ea19715b 100644--- a/packages/native/specs/swift/library/component-api.md+++ b/packages/native/specs/swift/library/component-api.md@@ -141,9 +141,11 @@ same generated contract.## Current state- `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`).+ (SwiftUI views with core's names, `Button`, `Text`, and so on, re-exporting+ SwiftUI and the contracts) and the `AstryxNative` product (generated contract+ types, unprefixed: `ButtonProps`, `ButtonVariant`).+- All six views still take hand-written parameters until each moves onto its+ generated `<Name>Props`; Banner has no generated contract.- The generated iOS `SwitchProps` still declares `size`, and `HStackProps` and`VStackProps` are still generated for iOS and macOS.