Repository navigation
spec(native): Swift component API takes the generated contract in SwiftUI's shape - #8035
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report
|
|
/approve-spec f98b552 |
There was a problem hiding this comment.
Requesting changes: the direction is owner-approved, but the record states Swift behavior that does not hold and conflicts with two current specs that it leaves unamended.
- A1a: in a file that imports both SwiftUI and
Astryx, an unqualifiedButtonorTextis ambiguous (ambiguous use of 'Button','Text' is ambiguous for type lookup), so the rule, its acceptance check and the docs guidance need restating, or the prefix kept. - A6 forbids the
color,paddingandelevationparameters that the generated contracts carry and AST-082 FR3 keeps; limit it to visual parameters outside the contract. - A4's
Bindingand A5'sLocalizedStringResourcespelling depart from AST-093 FR5 ("named and typed as the generated contract") and fail A2's own check; amend FR5 or narrow A2. - Current state describes the unmerged swift-ios-1 package rather than
main'sAstryxNative, and A1b's list should requalify Foundation'sTimerand coverCalendarandSelector.
The corrected head will need a fresh /approve-spec.
[Automated review]
| - **A1a — Two spellings, one view.** `Button(…)` and the module-qualified | ||
| `Astryx.Button(…)` name the same view. In a file that imports both SwiftUI | ||
| and `Astryx`, the unqualified name means Astryx's view, because a module's | ||
| own types take precedence over those of a module it imports. The system | ||
| view is written `SwiftUI.Button`. Documentation and examples write | ||
| `Astryx.Button` wherever SwiftUI's view of the same name appears in the same | ||
| file. |
There was a problem hiding this comment.
In a file that imports both SwiftUI and Astryx, Swift does not prefer Astryx's Button: a module's own types win only inside that module. A two-module compile probe gives ambiguous use of 'Button' for a call both initializers accept and 'Text' is ambiguous for type lookup in this context in a type position, with or without @_exported import SwiftUI. Only a file that imports Astryx alone, with SwiftUI re-exported, gets the bare name. Suggest restating A1a that way and updating the A1a check (line 84) and the Summary, or keeping the prefix.
| names that SwiftUI also declares today are `Button`, `ContextMenu`, | ||
| `Divider`, `Grid`, `HStack`, `Layout`, `Link`, `List`, `Section`, `Slider`, | ||
| `Stepper`, `Tab`, `Table`, `TableRow`, `Text`, `Timer`, and `VStack`; a new | ||
| component whose name SwiftUI declares joins this list. |
There was a problem hiding this comment.
Timer is Foundation's type, not SwiftUI's. If the list means names visible under import SwiftUI, which re-exports Foundation, it also needs Foundation's Calendar and Objective-C's Selector, both core components (Selector already has a generated Swift contract). Qualify each with its own module: Foundation.Timer, Foundation.Calendar, ObjectiveC.Selector.
| - A value prop paired with its change callback in the core contract is a | ||
| `Binding` (`value:`). | ||
| - A typed slot (AST-082 FR4) is a generic `@ViewBuilder` parameter | ||
| constrained to the slot's kind, never `AnyView`. | ||
| - Parameters with defaults come after those without. | ||
| - **A5 — Words have a localizable spelling.** Each word parameter has a | ||
| `LocalizedStringResource` spelling, looked up in the caller's bundle when it | ||
| is shown, beside the contract's `String` spelling, shown as given. Both set | ||
| the same prop. |
There was a problem hiding this comment.
A4's value: Binding (Switch, TextInput and Selector pair value with onChange) and A5's LocalizedStringResource spelling are parameters that are not props of the generated <Name>Props, so they fail A2's own check (line 87) and depart from AST-093 FR5 ("parameters named and typed as the generated contract"), which stays unamended. Either amend AST-093 FR5 and narrow A2 to the props initializer, or drop these spellings until FR5 allows them.
| - **A6 — No styling parameters.** A view has no color, font, padding, corner, or | ||
| shadow parameter and no public `*Style` protocol. Visuals come from the | ||
| theme (AST-082 DEC-2). Layout around the component stays with the caller's | ||
| own modifiers. |
There was a problem hiding this comment.
As written, this forbids color (Text, Heading), padding and its variants (Card, HStack, VStack) and elevation (Button, Card): core props that A2 makes parameters and that AST-082 FR3 says a platform never removes. The check on line 92 already targets SwiftUI Color, Font, CGFloat padding and *Style; suggest limiting the text to visual parameters the contract lacks.
| - The SwiftUI views are named with an `Astryx` prefix (`AstryxButton`, | ||
| `AstryxText`), the module is `AstryxCore`, and the theme types are | ||
| `AstryxTheme` and `AstryxTokens`; the theme generator spec uses the same | ||
| prefixed theme names. | ||
| - The SwiftUI views for Banner, Button, Card, Heading, Text, and TextInput | ||
| declare their own enums (for example `AstryxButtonVariant`) and do not | ||
| import the generated contract types. | ||
| - The Button view adds `icon` and `fillsWidth`, which the contract lacks, and | ||
| leaves out the contract's `elevation`, `isInterruptible`, `tooltip`, and | ||
| `href`. | ||
| - Every word parameter is a `String`. |
There was a problem hiding this comment.
This describes the unmerged swift-ios-1 package (AstryxCore, AstryxButton, icon, fillsWidth), not main. On main the only Swift package is packages/native/apple, whose product and module are AstryxNative, with generated contracts and no SwiftUI views. Please describe main and name the AstryxNative to Astryx rename that A1 implies.
|
/approve-spec b70015d |
There was a problem hiding this comment.
Requesting changes: the direction is owner-approved and the earlier points are fixed, but A4's slot rule conflicts with the rest of the record. A4 makes every typed slot a @ViewBuilder generic, yet the generated <Name>Props leaves content slots out (Card, HStack, VStack), so A3's "body reads only that value" and the A2/A5 checks ("no public parameter outside the generated <Name>Props") cannot hold, while text slots (Text, Heading, Badge, Divider) are String under A5 and AST-093 FR5. Scoping A4 to content slots, as the typed-slots draft in #8037 does, and adjusting A3 and the two checks resolves it; the corrected revision will need a fresh /approve-spec.
- Smaller: A2 names only
iosplatform props, while the macOSSelectorPropsalso carries amacosmenuStyle. - Smaller: in a file that imports both modules, a call that fits only one initializer compiles without error, so A1a's "fails loudly" holds for type positions only.
[Automated review]
| - A typed slot (AST-082 FR4) is a generic `@ViewBuilder` parameter | ||
| constrained to the slot's kind, never `AnyView`. |
There was a problem hiding this comment.
A text slot is a String field of the generated <Name>Props (Text and Heading children, Badge and Divider label), which A2, A5 and AST-093 FR5 keep, while a content slot is left out of <Name>Props (packages/native/src/contract/generateSwift.ts:132-137). So the builder this bullet requires fails the A2/A5 checks (lines 94 and 98) for Card, HStack and VStack, and their children are outside the value A3's body reads (line 61). Suggest scoping this bullet to content slots, saying text slots are words under A5, and adjusting A3 and the two checks for content builders.
| - **A2 — The contract is the parameter list.** Every core prop and `ios` | ||
| platform prop of the generated `<Name>Props` is a parameter of the view with |
There was a problem hiding this comment.
The package also builds for macOS (Package.swift, .macOS(.v14)), and Selector declares menuStyle under macos (packages/native/src/components/Selector.ts:37-42). Suggest "every core prop and every platform prop of the generated <Name>Props for the platform being built".
| - In a file that also imports SwiftUI directly, or another module that | ||
| declares the same name, an unqualified shared name is ambiguous to Swift, | ||
| so the file writes `Astryx.Button` and `SwiftUI.Button`. |
There was a problem hiding this comment.
Type positions and calls that both initializers accept are ambiguous, but a call that only one module's initializer accepts compiles against that module without an error, so for calls the qualifier is a convention rather than something the compiler enforces. The A1a check (line 91) could add such a call.
|
/approve-spec e022f2f |
There was a problem hiding this comment.
Requesting changes: the earlier slot conflict is fixed, but this revision's A4 now lets a content slot accept any SwiftUI view, while current AST-082 FR4 gives non-React platforms only a typed slot of named Astryx components and keeps free-form content to the web and React-running contracts. The allowance A4 relies on is the FR4 amendment proposed in #8070, and the slots.md it cites exists only in #8037. Either narrow A4's builder to the Astryx components the core slot names and drop the path (a new commit needs a fresh /approve-spec), or hold this revision until #8070 and #8037 land and have it reviewed again.
- Smaller: A4's "a required action comes last" (line 73) and "parameters with defaults come after those without" (line 79) give two orders for a component with a required callback.
- Smaller: the PR description's Decision list still describes A4 with a
Bindingand builders for every typed slot.
[Automated review]
| - A `content` slot (AST-082 FR4) is a generic `@ViewBuilder` closure | ||
| parameter that accepts any view, as | ||
| `packages/native/specs/swift/library/slots.md` says, never `AnyView`. A |
There was a problem hiding this comment.
This content slot accepts any SwiftUI view, but current AST-082 FR4 gives non-React platform contracts only a typed slot (named Astryx components) and keeps free-form content to the web and React-running contracts. The wider-form allowance is the FR4 amendment in #8070, and slots.md exists only in #8037. Suggest limiting the builder to the Astryx components the core slot names, as "constrained to the slot's kind" did, and dropping the path, or merging after #8070 and #8037 land.
| `packages/native/specs/swift/library/slots.md` says, never `AnyView`. A | ||
| `text` slot is words, a `String` field of `<Name>Props` (A5), and an `icon` | ||
| slot is an `IconName` field. | ||
| - Parameters with defaults come after those without. |
There was a problem hiding this comment.
With line 73 this gives two orders for a component with a required callback and a defaulted parameter: the required action has no default yet comes last. Suggest stating the trailing action as the exception.
|
/approve-spec 0156851 |
There was a problem hiding this comment.
Requesting changes: A4 still lets a content slot accept any SwiftUI view, which current AST-082 FR4 allows only for the web and React-running contracts, and the amendment it relies on is still open in #8070. Land #8070 first and ask for a fresh review, or narrow A4's builder to the Astryx components the core slot names; any new commit needs a fresh /approve-spec.
- A4 cites
packages/native/specs/swift/library/slots.md, which only #8037 adds, so add #8037 to the landing order or drop the path. - A3 gives the props initializer the same content builders as the labeled one, while
slots.mdin #8037 has it take the generated node type; please align the two records.
[Automated review]
| - A `content` slot (AST-082 FR4, with its amendment that lets a platform | ||
| accept a wider form for a content slot) is a generic `@ViewBuilder` | ||
| closure parameter that accepts any view, as | ||
| `packages/native/specs/swift/library/slots.md` says, never `AnyView`. A |
There was a problem hiding this comment.
This content slot accepts any SwiftUI view, but current AST-082 FR4 keeps free-form content to the web contract and React-running platform contracts and gives every other contract a typed slot of named Astryx components. The amendment named here is only proposed in #8070, and slots.md exists only in #8037, so on today's main this sentence contradicts FR4 and points at a missing file. Land #8070 (and #8037) first, or narrow the builder to the Astryx components the core slot names and drop the path.
| - **A3 — Two ways in, one meaning.** The view has an initializer that takes | ||
| `<Name>Props`, for generated and wire-driven callers, and a SwiftUI-style | ||
| initializer with labeled parameters. Both build the same `<Name>Props` and | ||
| take the same content-slot builders, and the view's `body` reads only that | ||
| value and those builders. |
There was a problem hiding this comment.
A3, and the A2 compile check on line 107, give the props initializer the same content-slot builders as the labeled initializer, while slots.md S3 in #8037 says "The props initializer takes the slot as the matching generated node type." Since A4 defers to slots.md for the slot form, please let one record own the props initializer's content parameter and align the other.
| `SwiftUI.Button`. There, Swift rejects an unqualified shared name in a type | ||
| position, and in a call that both modules' initializers accept, as | ||
| ambiguous; a call that only one module's initializer accepts compiles | ||
| against that module, so for such calls the qualifier is this rule, not a | ||
| compiler error. |
There was a problem hiding this comment.
Worth testing before relying on: Swift reports this ambiguity only when the two initializers tie in overload ranking, and it ranks a string literal's default type String above LocalizedStringKey, so with A5's String words a plain Text("Saved") in a file importing both modules should resolve to Astryx.Text without an error. Adding a call like Text("x") to the A1a compile check (line 103) would settle which way it goes.
|
/approve-spec 822cd49 |
There was a problem hiding this comment.
Requesting changes: A4 still lets a content slot accept any SwiftUI view, which current AST-082 FR4 allows only for the web and React-running contracts, and the amendment it relies on is still open in #8070. Land #8070 first and ask for a fresh review, or narrow A4's builder to the Astryx components the core slot names; any new commit needs a fresh /approve-spec.
- This record lands after #8037, but #8037 says it lands after this record and cites its OQ1, so land the two together or drop one of the cross-references.
- The A1a check
let a: Astryx.Text = Text("x")compiles whichever initializer ranks first; checklet a = Text("x")and its type in a separate statement instead.
[Automated review]
| initializer with labeled parameters. Both build the same `<Name>Props`. The | ||
| labeled initializer takes each content slot as a `@ViewBuilder` closure, and | ||
| the props initializer takes it as the slot's generated node type, as | ||
| `packages/native/specs/swift/library/slots.md` says; the view's `body` reads |
There was a problem hiding this comment.
slots.md exists only in #8037, and #8037's description says it lands after this pull request (its S1 also cites this record's OQ1), while this description says this record lands after #8037. Followed as written, neither can land first. Suggest landing the two records together, or dropping one direction of the cross-reference (for example, stating the props initializer's node type and IconName here) and making the landing orders agree.
| | Requirement | Check | | ||
| | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | ||
| | A1 | The package manifest names the library product and module `Astryx`; a source check finds no type named `Astryx` in it. | | ||
| | A1a | A compile test with two app files: one importing only `Astryx` checks that `let a: Button = Button("x") {}` is `Astryx.Button` and `SwiftUI.Button("x") {}` is SwiftUI's; one importing SwiftUI and `Astryx` checks that `Astryx.Button` and `SwiftUI.Button` both resolve, that `let t: Text` does not compile there (ambiguous in a type position), that `let a: Astryx.Text = Text("x")` compiles there (a string-literal call both initializers accept resolves to Astryx's), and that a call only Astryx's initializer accepts, `Button("x", variant: .primary) {}`, compiles as `Astryx.Button`. | |
There was a problem hiding this comment.
let a: Astryx.Text = Text("x") gives the call a contextual type that only Astryx's initializer satisfies, so it compiles whichever initializer would rank first without the annotation and cannot show the ranking the parenthesis states. Suggest let a = Text("x") followed by a separate let _: Astryx.Text = a.
|
/approve-spec 35e55fc |
There was a problem hiding this comment.
Requesting changes: A4 still lets a content slot accept any SwiftUI view, which current AST-082 FR4 allows only for the web and React-running contracts, and the amendment it relies on is still open in #8070. Land #8070, then #8037 (which adds the cited slots.md and IconName), and ask for a fresh review, or narrow A4's builder to the Astryx components the core slot names; any new commit needs a fresh /approve-spec.
- A2 still calls a content slot a
@ViewBuilderparameter of every initializer, and its source check rejects the<Name>Propsparameter that A3's props initializer takes; please align both with A3. - A8's doc comment that "names the core prop it maps to" and the A3 check's "equal
<Name>Props" cannot be met as worded, since some public declarations map to no prop and the generated props hold closures and are notEquatable.
[Automated review]
| same default. A `content` slot, which `<Name>Props` leaves out, is a | ||
| `@ViewBuilder` parameter of the view's initializers instead (A4). The view |
There was a problem hiding this comment.
A3 (lines 70–72) gives the props initializer each content slot as its generated node type, so this sentence holds only for the labeled initializer. Suggest "a @ViewBuilder parameter of the labeled initializer (A3)". The A2 source check (line 110) also needs to allow the <Name>Props parameter A3's props initializer takes, which is neither a prop of <Name>Props nor a content slot.
| - **A8 — Every public declaration has a one-sentence doc comment** that names | ||
| the core prop it maps to. |
There was a problem hiding this comment.
The view type, body, the props initializer and <Name>Props itself map to no single core prop, so this cannot be met as worded. Suggest "names the core prop it maps to, where it maps to one".
| | 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` 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. | | ||
| | A3 | A test shows the labeled initializer and the props initializer produce equal `<Name>Props` for the same arguments. | |
There was a problem hiding this comment.
The generated props are not Equatable and hold closures (ButtonProps.onClick, SelectorProps.onChange), so "equal <Name>Props" is undefined for them. Suggest naming what the test compares, such as every non-callback field and each callback reaching the same action.
|
/approve-spec 50e537e |
50e537e to
dd9d796
Compare
|
/approve-spec dd9d796 |
There was a problem hiding this comment.
Requesting changes: the record conforms to current AST-082 and AST-093 and carries an engineering owner's /approve-spec for this revision, but A3 and A4 cite packages/native/specs/swift/library/slots.md, which is not on main or in this branch yet. Because this branch's README row conflicts with the one #8037 adds, this revision can only merge before #8037, which would leave both citations pointing at a missing file. Please land #8037 first and rebase (rows in order: accessibility.md, component-api.md, slots.md, theme-generator.md), or drop the two citations since A3 and A4 already state the slot forms, then request review of the new head.
[Automated review]
| generated node type, as `packages/native/specs/swift/library/slots.md` says, | ||
| and both build the view from the same `<Name>Props` values; the view's `body` | ||
| reads only those values and slots. | ||
| - **A4 — SwiftUI shapes for SwiftUI concepts.** | ||
| - The component's main word comes first and unlabeled, as in `Button` and | ||
| `Text`. | ||
| - A `content` slot (AST-082 FR4, with its amendment that lets a platform | ||
| accept a wider form for a content slot) is a generic `@ViewBuilder` | ||
| closure parameter that accepts any view, as | ||
| `packages/native/specs/swift/library/slots.md` says, never `AnyView`. A |
There was a problem hiding this comment.
slots.md is not on main or in this branch; it exists only in #8037. Once #8037 lands, this branch's README row conflicts with its slots.md row, so this revision can merge unchanged only before #8037, leaving both citations pointing at a missing file. Land #8037 and rebase, or drop the two citations, since A3 and A4 already state the forms.
dd9d796 to
1579770
Compare
|
/approve-spec 1579770 |
There was a problem hiding this comment.
Recommending approval: the record conforms to current AST-082 and AST-093, an engineering owner's /approve-spec covers this revision, and the slots.md citations now resolve on main. Two optional wording fixes are left inline: A3's check could say whether slots.md S3's per-slot convenience initializers count, and A4 can cite AST-082 FR4 directly instead of "with its amendment". The theme generator spec still names AstryxTheme and AstryxTokens, so landing #8038 next keeps the two records consistent.
[Automated review]
| - **A4 — SwiftUI shapes for SwiftUI concepts.** | ||
| - The component's main word comes first and unlabeled, as in `Button` and | ||
| `Text`. | ||
| - A `content` slot (AST-082 FR4, with its amendment that lets a platform |
There was a problem hiding this comment.
Non-blocking: AST-082 FR4 itself now carries the wider-form sentence, so "with its amendment" reads as change history (writing rubric R1). Suggest: "A content slot (AST-082 FR4, which lets a platform accept a wider form for a content slot) …".
| | 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. | | ||
| | 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. | |
There was a problem hiding this comment.
Non-blocking: slots.md S3 also gives a view one convenience initializer per Astryx component its content slot names (for example startContent: AvatarProps). Consider saying whether those must build the same <Name>Props too, for example "through each initializer, the slot convenience initializers included".
Exact decision needed
How a SwiftUI view in
@astryxdesign/nativeis named and exposes its component's generated contract: core names in a module namedAstryx, the parameter list for each platform, the two initializers, SwiftUI shapes for actions and content slots, the contract's types for words and values, and what a view never offers. Approved by the owner; this description matches the current head.Existing authority searched
spec:AST-082(current): core and platform contracts (FR3), portable props and typed slots (FR4), platform-scoped Swift bindings generated from the same contract (FR5), base props (FR7), naming (FR8), visuals in the theme rather than props (DEC-2).spec:AST-093(current): parameters named and typed as the generated contract (FR5). A5 follows it; SwiftUI spellings that convert to contract types are OQ1.packages/native/specs/swift/library/slots.md) sets the slot forms A4 uses.Decision
Astryx(import Astryx, thenButton,Text,Theme,ButtonProps);Astryxre-exports SwiftUI and the generated contracts; generated wire types keep their names; no type namedAstryx.Button(…)andAstryx.Button(…)are the same view. A file that imports onlyAstryxgets Astryx's type for an unqualified shared name. A file that also imports SwiftUI writesAstryx.Button/SwiftUI.Button: there Swift rejects an unqualified shared name in a type position; a string-literal call both initializers accept resolves to Astryx's view (Stringranks aboveLocalizedStringKey), and a call only one initializer accepts compiles against that one, so for calls the qualifier is the rule.CalendarandTimerfrom Foundation,Selectorfrom ObjectiveC..astryxTheme(_:).<Name>Propsfor the platform being built (ios,macos, such as Selector'smenuStyle) is a parameter with the same name, type, and default; content slots, which<Name>Propsleaves out, are@ViewBuilderparameters; no Swift-only enums or props.@ViewBuilderclosures and the props one as their generated node types, asslots.mdsays;bodyreads only those.@ViewBuilderclosures, neverAnyView; text slots areStringfields, icon slotsIconNamefields.LocalizedStringResourceandBindingspellings are OQ1, an AST-093 FR5 amendment decided outsidepackages/native/.idandisHiddenmap once, on the contract's base target.Rejected alternatives
None recorded in the spec.
Claim scope and non-goals
Tokens and theming, accessibility semantics, Dynamic Type, and per-component behavior are separate specs. Renaming the existing views and bringing them onto the generated contract is a later pull request.
Landing order
Lands after the AST-082 FR4 amendment (#8070), which A4's open content slots rely on, and after the typed slots spec (#8037), whose
slots.mdA3 and A4 cite.Evidence and implementation relationship
One file:
packages/native/specs/swift/library/component-api.md.Writing rubric results
Scope
packages/native/.Name resolution evidence
Checked with
swiftc(Swift 6, macOS 14 SDK) on two modules: a contracts module re-exported by a views module namedAstryxthat declaresButtonandTextand re-exports SwiftUI.import Astryx:let t: Text = Text("x")andlet b: Button = Button("x") {}compile and areAstryx.Text/Astryx.Button;SwiftUI.Toggle(…)resolves.import SwiftUIandimport Astryx:let t: Text = Text("x")fails with'Text' is ambiguous for type lookup in this context;Astryx.TextandSwiftUI.Textboth resolve;let a = Text("Hello")andlet b = Button("Save") {}compile and areAstryx.Text/Astryx.Button.import SwiftUIthat core also uses, from a compile probe over all 173 core component names: Button, Calendar, ContextMenu, Divider, Grid, HStack, Layout, Link, List, Section, Selector, Slider, Stepper, Tab, Table, TableRow, Text, Timer, VStack.