Repository navigation
feat(native): Swift Text and Heading take core's props - #8303
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 Regression48 of 502 shot(s) changed. A change here is a question, not a failure: check whether the after is the
and 28 more. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
10923a6 to
44ac0b4
Compare
There was a problem hiding this comment.
Moving Swift Text and Heading onto the generated TextProps and HeadingProps follows AST-093 FR5, but approval waits on an engineering owner deciding the reworded draft theme-generator G5, which makes the Swift generator keep text-display-* and text-code-*. An engineering owner records that decision by commenting /approve-spec 44ac0b49fe25971b5d50a28225c58dd35d089351 on this pull request, and the author may do so if they are an engineering owner. Whatever that decision, these still need changes:
- Text's
display-1todisplay-3use the body family (TypeStyle.swiftlines 20–22) where core uses the heading family, so Stone, Matcha and Chocolate show a different typeface on iOS than on the web. textInitializersBuildTheSameProps,textColorDefaultsByTypeAsCoreDoesandheadingInitializersBuildTheSamePropsneed@MainActor, because they call main-actor-isolated view members from nonisolated tests, which Swift 6 rejects.justifyhas no effect on a one-lineHeading(Heading.swiftline 60), which core aligns across the heading's full width.astryxLineLimittraps on an infinite or very largemaxLines(TypeStyle.swiftlines 104–107).- AST-093 FR5 still needs the Swift tests run on this head and simulator captures in light, dark and the largest text size.
[Automated review]
| case .display1: TypeStyle(size: display1Size, weight: display1Weight, families: familyBody) | ||
| case .display2: TypeStyle(size: display2Size, weight: display2Weight, families: familyBody) | ||
| case .display3: TypeStyle(size: display3Size, weight: display3Weight, families: familyBody) |
There was a problem hiding this comment.
Core draws Text display-1 to display-3 in the heading family: expandTypeScale.ts maps them to var(--font-family-heading), and every theme that defines typography (Stone, Matcha, Chocolate, Neutral, …) applies it. With familyBody here, iOS shows Figtree, DM Sans or Albert Sans where the web shows Montserrat, Playwrite US Trad or Fraunces, and Text(type: .display1) does not match Heading(type: .display1). Suggest families: familyHeading for these three cases, plus a family assertion in everyTypeReadsItsOwnTokens.
| // Swift component API spec, A2 and A3: Text takes core's Text props, and both | ||
| // initializers build it from the same TextProps. | ||
|
|
||
| @Test func textInitializersBuildTheSameProps() { |
There was a problem hiding this comment.
This test, and textColorDefaultsByTypeAsCoreDoes below, build Astryx.Text or call its static defaultColor without @MainActor. The package compiles in Swift 6 mode and SwiftUI's View is @MainActor, so those members are main-actor isolated and a synchronous call from a nonisolated @Test is a compile error that takes the whole AstryxTests target down. Every other view-building test here is marked @MainActor; adding it to both fixes this.
| #expect(Astryx.Heading("Sidebar", level: .v2, accessibilityLevel: .v3).headingLevel == .h3) | ||
| } | ||
|
|
||
| @Test func headingInitializersBuildTheSameProps() { |
There was a problem hiding this comment.
Same as in TextTests.swift: building Astryx.Heading and reading props from a nonisolated @Test does not compile in Swift 6 mode, because View makes them main-actor isolated. Marking the test @MainActor fixes it.
| public var body: some View { | ||
| styled(SwiftUI.Text(props.children)) | ||
| .lineLimit(astryxLineLimit(props.maxLines)) | ||
| .multilineTextAlignment(props.justify?.alignment ?? inheritedAlignment) |
There was a problem hiding this comment.
multilineTextAlignment aligns lines only inside the Text's own frame, and a one-line Text hugs its words, so justify: .center or .end has no visible effect on a short heading. Core's Heading is a block, so text-align centers or end-aligns even one line across its container. Adding .frame(maxWidth: .infinity, alignment:) with the matching alignment when justify is set would match core.
| func astryxLineLimit(_ maxLines: Double?) -> Int? { | ||
| guard let maxLines, maxLines >= 1 else { return nil } | ||
| return Int(maxLines) | ||
| } |
There was a problem hiding this comment.
Int(maxLines) traps for .infinity and for values of 2^63 or more, both of which pass maxLines >= 1. Also requiring maxLines.isFinite && maxLines < Double(Int.max) (and treating anything else as no limit) avoids crashing on a value the public Double? allows.
e953635 to
7f2363a
Compare
44ac0b4 to
c7c537e
Compare
There was a problem hiding this comment.
Moving Swift Text and Heading onto the generated TextProps and HeadingProps follows AST-093 FR5, but approval waits on an engineering owner deciding the reworded draft theme-generator G5, which makes the Swift generator keep the text-display-* and text-code-* token groups. An engineering owner records that decision by commenting /approve-spec <full head SHA> on this pull request, and the author may do so if they are an engineering owner. Whatever that decision, these still need changes:
- Text
display-1todisplay-3use the body family (TypeStyle.swiftlines 20–22) where core uses the heading family, so Chocolate, Matcha and Stone show a different typeface on iOS than on the web. textInitializersBuildTheSameProps,textColorDefaultsByTypeAsCoreDoesandheadingInitializersBuildTheSamePropsneed@MainActor, because the package builds in Swift 6 mode, where calling a view's members from a nonisolated test does not compile.justifyhas no effect on a one-lineHeading(Heading.swiftline 60), which core aligns across the container.astryxLineLimittraps on an infinite or very largemaxLines(TypeStyle.swiftlines 104–106).Text(type: .inherit, size:)switches to the body family while its doc says it keeps the surrounding font; document that limit as a contract gap.- AST-093 FR5 still needs the Swift tests run on this head and simulator captures in light, dark and the largest text size.
[Automated review]
| case .display1: TypeStyle(size: display1Size, weight: display1Weight, families: familyBody) | ||
| case .display2: TypeStyle(size: display2Size, weight: display2Weight, families: familyBody) | ||
| case .display3: TypeStyle(size: display3Size, weight: display3Weight, families: familyBody) |
There was a problem hiding this comment.
Core draws Text display-1 to display-3 in the heading family: expandTypeScale.ts maps them to var(--font-family-heading), and every theme that declares typography applies it. With familyBody here, Chocolate, Matcha and Stone show Albert Sans, DM Sans or Figtree on iOS where the web shows Fraunces, Playwrite US Trad or Montserrat, and Text(type: .display1) differs from Heading(type: .display1). Suggest families: familyHeading for these three cases, plus a family assertion in everyTypeReadsItsOwnTokens.
| func astryxLineLimit(_ maxLines: Double?) -> Int? { | ||
| guard let maxLines, maxLines >= 1 else { return nil } | ||
| return Int(maxLines) |
There was a problem hiding this comment.
Int(maxLines) traps for .infinity and for values of 2^63 or more, both of which pass maxLines >= 1, and the public Double? and the wire decoder accept them. Also requiring maxLines.isFinite && maxLines < Double(Int.max), and treating anything else as no limit, avoids the crash.
| public var body: some View { | ||
| styled(SwiftUI.Text(props.children)) | ||
| .lineLimit(astryxLineLimit(props.maxLines)) | ||
| .multilineTextAlignment(props.justify?.alignment ?? inheritedAlignment) |
There was a problem hiding this comment.
multilineTextAlignment aligns lines only inside the text's own frame, and a one-line Text hugs its words, so justify: .center or .end has no visible effect on a short heading. Core's Heading is a block, so text-align centers or end-aligns even one line across its container. Adding .frame(maxWidth: .infinity, alignment:) with the matching alignment when justify is set would match core.
| } else if let size = props.size { | ||
| // `inherit` with a size: SwiftUI cannot change only the size of an | ||
| // inherited font, so it draws the body family at that size. | ||
| let weight = font.weight(named: props.weight?.rawValue ?? "normal") | ||
| text = text.font(astryx.font(TypeStyle(size: font.size(size), weight: weight, families: font.familyBody))) |
There was a problem hiding this comment.
For inherit with a size, this draws the body family at normal weight, while the type doc above says inherit keeps the surrounding font. Core changes only the size and keeps the inherited family and weight. If SwiftUI cannot do that, please say so in the type and size doc comments and report the case as a contract gap (AST-082 FR3) rather than substituting silently.
| // Swift component API spec, A2 and A3: Text takes core's Text props, and both | ||
| // initializers build it from the same TextProps. | ||
|
|
||
| @Test func textInitializersBuildTheSameProps() { |
There was a problem hiding this comment.
This test, and textColorDefaultsByTypeAsCoreDoes below, build Astryx.Text or call its static defaultColor from a nonisolated @Test. The package builds in Swift 6 mode (swift-tools-version: 6.0) and SwiftUI's View is main-actor isolated, so those calls do not compile and take the whole AstryxTests target down. Every other view-building test here is @MainActor; adding it to both fixes this.
| #expect(Astryx.Heading("Sidebar", level: .v2, accessibilityLevel: .v3).headingLevel == .h3) | ||
| } | ||
|
|
||
| @Test func headingInitializersBuildTheSameProps() { |
There was a problem hiding this comment.
Same as in TextTests.swift: building Astryx.Heading and reading props from a nonisolated @Test does not compile in the package's Swift 6 mode. Marking the test @MainActor fixes it.
c7c537e to
bd51b1b
Compare
There was a problem hiding this comment.
Moving Swift Text and Heading onto the generated TextProps and HeadingProps follows AST-093 FR5, and the Swift tests now pass on macOS and the iOS Simulator, but approval waits on an engineering owner deciding the reworded draft theme-generator G5, which makes the Swift generator keep the text-display-* and text-code-* token groups. An engineering owner records that decision by commenting /approve-spec <full head SHA> on this pull request, and the author may do so if they are an engineering owner. Whatever that decision, these still need changes:
- Text
display-1todisplay-3use the body family (TypeStyle.swiftlines 20–22) where core uses the heading family, so Chocolate, Matcha and Stone show a different typeface on iOS than on the web. justifyhas no effect on a one-lineHeading(Heading.swiftline 60), which core aligns across its container.astryxLineLimittraps on an infinite or very largemaxLines(TypeStyle.swiftlines 104–107).Text(type: .inherit, size:)switches to the body family while its doc says it keeps the surrounding font; document that limit as a contract gap.- With
maxLinesunset, both views apply.lineLimit(nil)(Text.swiftline 58,Heading.swiftline 59), which overrides a caller's own.lineLimit. - AST-093 FR5 still needs simulator captures in light, dark and the largest text size.
[Automated review]
| .font(astryx.font(size: sizeToken, 14, weight: weightToken)) | ||
| .foregroundStyle(astryx.color((color ?? type.defaultColor).token)) | ||
| styled(SwiftUI.Text(props.children)) | ||
| .lineLimit(astryxLineLimit(props.maxLines)) |
There was a problem hiding this comment.
With maxLines unset this is .lineLimit(nil). SwiftUI's line limit is an environment value and the innermost setting wins, so a caller's Astryx.Text(bio).lineLimit(2), or a limit on a containing stack, no longer clamps the text as it did before this change; Heading.swift line 59 does the same. Reading @Environment(\.lineLimit) and falling back to it when maxLines is unset, as inheritedAlignment already does for alignment, keeps the caller's limit.
There was a problem hiding this comment.
Moving Swift Text and Heading onto the generated TextProps and HeadingProps follows AST-093 FR5, and the earlier display-family, justify and maxLines crash findings are fixed, but approval waits on an engineering owner deciding the reworded draft theme-generator G5, which makes the Swift generator keep the text-display-* and text-code-* token groups. An engineering owner records that decision by commenting /approve-spec <full head SHA> on this pull request, and the author may do so if they are an engineering owner. Whatever that decision, these still need changes:
- With
maxLinesunset, both views apply.lineLimit(nil)(Text.swiftline 58,Heading.swiftline 59), which overrides a caller's own.lineLimit. Text(type: .inherit, size:)switches to the body family while its doc comment saysinheritkeeps the surrounding font; state that limit in the doc comments and record it as a contract gap.- AST-093 FR5 still needs simulator or device captures in light, dark and the largest text size.
[Automated review]
There was a problem hiding this comment.
Moving Swift Text and Heading onto the generated TextProps and HeadingProps follows AST-093 FR5, and the line-limit, inherit-with-size and capture findings from the previous revision are resolved. Approval now waits on an engineering owner deciding the reworded draft theme-generator G5, which makes the Swift generator keep the text-display-* and text-code-* token groups (12 new public FontTokens members in every generated theme). An engineering owner records that decision by commenting /approve-spec <full head SHA> on this pull request, and the author may do so if they are an engineering owner; if Swift should keep different groups, the owner names them instead.
[Automated review]
…-line Heading; maxLines never traps
…ent inherit with size
209d05c to
75da666
Compare
There was a problem hiding this comment.
Moving Swift Text and Heading onto the generated TextProps and HeadingProps follows AST-093 FR5, and the Swift tests and simulator captures for this revision are in place, but approval waits on two engineering-owner decisions. First, the reworded draft theme-generator G5, which makes the Swift generator keep the text-display-* and text-code-* groups (12 new public FontTokens members in every theme), needs an engineering owner to record the decision by commenting /approve-spec <full head SHA> on this pull request, or to name the groups Swift should keep instead; the author may do so if they are an engineering owner. Second, Text(type: .inherit, size:) draws the theme's body family at the normal weight where core keeps the inherited family and weight, which AST-082 FR3 does not allow, so an engineering owner needs to accept that documented gap for Swift or say what should change; if it is accepted, the size doc comment should also mention the weight. Nothing else needs to change.
[Automated review]
| } else if let size = props.size { | ||
| // `inherit` with a size: SwiftUI cannot change only the size of an | ||
| // inherited font, so it draws the body family at that size. | ||
| let weight = font.weight(named: props.weight?.rawValue ?? "normal") | ||
| text = text.font(astryx.font(TypeStyle(size: font.size(size), weight: weight, families: font.familyBody))) |
There was a problem hiding this comment.
With type: .inherit and a size, this draws the theme's body family at the normal weight, where core keeps the inherited family and weight (text.stylex.ts inherits both for inherit, and size only replaces the font size). AST-082 FR3 treats a prop honored only in part as breaking architecture:public-component-api INV2, so an engineering owner needs to accept this documented gap for Swift or name the change to make. If it is accepted, the size doc comment above should also say that the weight falls back to normal.
There was a problem hiding this comment.
Moving Swift Text and Heading onto the generated TextProps and HeadingProps follows AST-093 FR5, and the Swift tests and simulator captures are in place, but approval waits on two engineering-owner decisions. First, the reworded draft theme-generator G5, which makes the Swift generator keep the text-display-* and text-code-* groups (12 new public FontTokens members in every theme), needs an engineering owner to record the decision by commenting /approve-spec <full head SHA> on this pull request, or to name the groups Swift should keep instead; the author may do so if they are an engineering owner. Second, Text(type: .inherit, size:) draws the theme's body family at the normal weight where core keeps the inherited family and weight, which AST-082 FR3 does not allow, so an engineering owner needs to accept that documented gap for Swift or say what should change. Nothing else needs to change.
[Automated review]
|
/approve-spec ecf083c |
What changes for people
An iOS developer gets every Text and Heading option core offers, working the way core defines it:
Text("Revenue", type: .display1),Text("const x = 1", type: .code),Text(total, hasTabularNumbers: true),Text(bio, maxLines: 2),Heading("Sidebar", level: .v2, accessibilityLevel: .v3). Before, Swift Text drew four of core's nine types and none ofmaxLines,justify,hasStrikethrough, orhasTabularNumbers, and Heading took a plain number with no display types, weight, color, or accessibility level.What this does
TextandHeadingtake the generatedTextPropsandHeadingProps(AST-093 FR5; Swift component API A2, A3), with a labeled initializer that builds the same props: the words first and unlabeled, then core's props in contract order (A4), typed as the contract (A5).type: all of core's text types, from the theme's typed tokens (G9).codedraws in the code family;inheritkeeps the surrounding font and color.size,weight, andcolor(placeholder draws the secondary text color, as core does;inheritsets none). The default color follows core: secondary forsupporting, primary otherwise.maxLines(a positive count truncates; unset, a caller's own.lineLimitstill applies),justify(alignment of wrapped lines, start and end following the layout direction),hasStrikethrough,hasTabularNumbers.level, displaytype,weight,color,accessibilityLevel(the level VoiceOver reads).idsets the accessibility identifier;isHiddenremoves the view from layout and from assistive technology, as core'shiddendoes.text-<style>-*groups adddisplay-1todisplay-3andcode, the type styles core's Text and Heading draw. G5 asks for a new group to land in the same pull request as the first component that reads it; this is that pull request. The generator's kept set and the generated files change with it.Lands after #8299 (the Astryx names), which this branch builds on.
Contract gap
Text(type: .inherit, size:): SwiftUI cannot change only the size of an inherited font, so the text draws in the theme's body family at normal weight (or atweight, when set) at that size, where core keeps the inherited face and weight. The doc comments say so. Recorded as a contract gap for the Swift Text spec.Not in this pull request
Card, TextInput, and Button move onto their generated props in the following pull requests.
Captures (AST-093 FR5)
Capture set: iPhone 16 simulator, iOS 18.5, Xcode 16.4, built from this PR's head (
75da666). Each capture shows every text type including display (heading family) and code, colors, weights, strikethrough, tabular numbers,maxLineswithjustify, headings 1–6, a display heading, centered and secondary headings, and two themes.Accessibility tree: not measured in these captures; the Swift tests check names, traits and values.
Testing
xsmspelling;maxLinesclamping, with a pixel check that one line stays short;accessibilityLevel;swiftc -typecheckof both modules, the tests, and the templates passes; the Swift tests run in CI on the iOS Simulator.pnpm vitest run --project node packages/native/src/theme(the drift test over the regenerated files) passes.Every changed file is under
packages/native/.