Repository navigation
refactor(native): Swift themes write colors with SwiftUI's own initializer - #8437
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 0998e62 |
There was a problem hiding this comment.
Approval waits on an engineering owner's decision on the new draft requirement in packages/native/specs/swift/library/theme-generator.md G7 (generated colors written as Color(.sRGB, …) with exact decimals, and no color initializer of the package's own): an engineering owner records it by commenting /approve-spec <full head SHA> on this pull request once it is rebased, and the author may do so if they are an engineering owner. Independently, the branch conflicts with main, and two calls added on main still use the removed initializer:
- In
packages/native/apple/Tests/AstryxTests/CardTests.swift,anInsetRingDrawsInsideTheDefaultCardsBorder(lines 141 and 143 onmain) callsColor(astryxRGBA:); that file merges without a conflict, so switch both calls toColor(.sRGB, …)during the rebase or the Swift tests stop compiling. - Resolve the acceptance-table conflict in
theme-generator.md, keepingmain's inset-ring sentence, so CI, including the macOS Swift job, runs on the new head.
[Automated review]
|
|
||
| extension Color { | ||
| /// A color from `0xRRGGBBAA` in sRGB, the form the generated themes use. | ||
| public init(astryxRGBA value: UInt32) { |
There was a problem hiding this comment.
main gained two more callers after this branch was cut: anInsetRingDrawsInsideTheDefaultCardsBorder in Tests/AstryxTests/CardTests.swift (lines 141 and 143 on main) calls Color(astryxRGBA: 0xFF00FFFF) and Color(astryxRGBA: 0x00FFFFFF). That file merges without a conflict, so during the rebase please switch them to Color(.sRGB, red: 1, green: 0, blue: 1, opacity: 1) and Color(.sRGB, red: 0, green: 1, blue: 1, opacity: 1), or the Swift test target won't compile.
…lizer Generated themes write every color as SwiftUI's Color(.sRGB, red:green:blue:opacity:), each channel 0, 1, or the exact decimal of its 8-bit step over 255. The package's own Color(astryxRGBA:) and Color(astryxHex:) initializers, which duplicated SwiftUI, are removed; no other public API changes. Every theme is regenerated, Swift tests build colors with Color(.sRGB, ...) directly, and G7 says how a color is written.
0998e62 to
f2862cc
Compare
|
/approve-spec f2862cc |
There was a problem hiding this comment.
This is ready for approval: the draft G7 requirement in packages/native/specs/swift/library/theme-generator.md carries an engineering owner's /approve-spec for this head, every regenerated theme color keeps its exact value, and no caller of the removed Color(astryxRGBA:) or Color(astryxHex:) remains. No changes are needed; the Swift package builds and its tests pass on macOS and the iOS Simulator.
[Automated review]
Based on
main. #8420 (CSS reader) and #8422 (diagnostics) stack on this PR.User need
An iOS developer using Astryx sees two color initializers of Astryx's own,
Color(astryxRGBA:)andColor(astryxHex:), next to SwiftUI's. They do exactly what SwiftUI'sColor(.sRGB, red:green:blue:opacity:)already does, so they add API to learn and keep, and they make generated theme code read as Astryx-specific when it is plain SwiftUI.After this change:
Color(.sRGB, red: …, green: …, blue: …, opacity: …), readable by anyone who knows SwiftUI..astryxTheme,\.astryxTheme, and\.astryxstay).Problem and solution fit
Theme.swift: removesColor(astryxRGBA:)andColor(astryxHex:), the only Astryx-prefixedColorinitializers or helpers in the package (searched every.swiftfile underpackages/native/appleforinit(astryx,func astryx, andvar astryx; the other matches are view modifiers, environment values, and internal font and text helpers, none about color).swiftColor(space, hex), writesColor(.sRGB, red:green:blue:opacity:). Each 8-bit channel is0,1, or the exact decimal of its step over 255.Tokens.swiftis unchanged.Color(.sRGB, …)directly; the two tests of the removed initializers become one test that the generated default accent equalsColor(.sRGB, red: 0, green: 100 / 255, blue: 224 / 255, opacity: 1).Colorinitializer.Non-test
Sources/usages changed: none. The removed initializers were used only by the generated theme files (regenerated) and by tests.Current specification
packages/native/specs/swift/library/theme-generator.md(draft) owns how the generator writes values (G7); this PR amends G7 and Current state there.Public delta and caller burden
Removed (public, experimental canary-only package):
Generated theme files, before and after:
A caller who wrote
Color(astryxRGBA:)orColor(astryxHex:)switches toColor(.sRGB, …). A product theme regenerates with the same command and needs no other change.Design and alternatives
n / 255. Each decimal is the shortest form ofn / 255, so it is the sameDoubleSwift computes for100 / 255(the Swift test above compares them with==). Withn / 255in every channel, Swift's type checker took about 1.9 s per theme initializer (measured with-warn-long-expression-type-checking), about 3.5× the module's total type-check time; with decimals it is about 1.5× the old0xRRGGBBAAform. Rejected:n / 255literals, for that build-time cost in every app that builds Astryx.Existing authority searched
astryxRGBA,astryxHex,init(astryx,extension Color,Color(.sRGB,theme-generator.md,swift-ios-theme.packages/native/specs/swift/library/theme-generator.md(owner of how values are written; amended). No record names either initializer.Writing rubric results
Evidence
swiftc -typecheckpasses for the package, tests, and templates.Color(.sRGB, red: 0, green: 100 / 255, blue: 224 / 255, opacity: 1)with==, which is how the removed initializer built it.Scope
Testing