Skip to content

feat(native): Swift Text and Heading take core's props - #8303

Merged
cixzhang merged 6 commits into
mainfrom
native/swift-text-heading-props
Oct 25, 2026
Merged

cixzhang merged 6 commits into
mainfrom
native/swift-text-heading-props

Conversation

@cixzhang

@cixzhang cixzhang commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

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 of maxLines, justify, hasStrikethrough, or hasTabularNumbers, and Heading took a plain number with no display types, weight, color, or accessibility level.

What this does

  • Text and Heading take the generated TextProps and HeadingProps (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).
  • Every prop is honored with core's meaning:
    • type: all of core's text types, from the theme's typed tokens (G9). code draws in the code family; inherit keeps the surrounding font and color.
    • size, weight, and color (placeholder draws the secondary text color, as core does; inherit sets none). The default color follows core: secondary for supporting, primary otherwise.
    • maxLines (a positive count truncates; unset, a caller's own .lineLimit still applies), justify (alignment of wrapped lines, start and end following the layout direction), hasStrikethrough, hasTabularNumbers.
    • Heading level, display type, weight, color, accessibilityLevel (the level VoiceOver reads).
    • Base props: id sets the accessibility identifier; isHidden removes the view from layout and from assistive technology, as core's hidden does.
  • Spec change, theme generator G5: the kept text-<style>-* groups add display-1 to display-3 and code, 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.
  • The Login template and Banner use the new parameter order and types.
  • README: Text and Heading are off the interim-exemption list.

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 at weight, 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, maxLines with justify, headings 1–6, a display heading, centered and secondary headings, and two themes.

Light Dark Light, largest text Light, largest text, end Dark, largest text Dark, largest text, end
Text and Heading, Light Text and Heading, Dark Text and Heading, Light, largest text Text and Heading, Light, largest text, end Text and Heading, Dark, largest text Text and Heading, Dark, largest text, end

Accessibility tree: not measured in these captures; the Swift tests check names, traits and values.

Testing

  • New and updated Swift tests:
    • both initializers build the same props;
    • core's default colors and the placeholder color;
    • each type reads its own tokens (code family, display sizes);
    • xsm spelling;
    • maxLines clamping, with a pixel check that one line stays short;
    • display text larger than body;
    • a hidden Text takes no space;
    • Heading accessibilityLevel;
    • a display type replacing the level's look.
  • swiftc -typecheck of 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/.

@vercel

vercel Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Oct 25, 2026 10:19am UTC

Request Review

@astracat-bot

astracat-bot Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
❓ Needs maintainer input (for maintainers only) Oct 25, 2026, 11:40 AM UTC

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 24, 2026
@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR

🧪 Sandbox Preview

View Sandbox for this PR

No new or modified components detected.

Bundle Size Summary

No component packages changed.

Accessibility Audit

Status: No accessibility violations detected.

Visual Regression

48 of 502 shot(s) changed.

A change here is a question, not a failure: check whether the after is the
picture you intended. Record that review on the PR. Baseline maintenance is an
explicit dispatch of CI; this report never rewrites the baseline or adds a release gate.

component story theme mode pixels
Selector Indicator Space Bottom Sheet Narrow End RTL neutral light 753,933
Selector Indicator Space Bottom Sheet Wide Start neutral light 740,072
RichTextEditor Markdown parity: side by side probe dark 556,900
RichTextEditor Markdown parity: side by side probe light 538,816
Chat Full AI Chat probe light 230,823
Chat Full AI Chat probe dark 229,805
AppShell With Mobile Nav probe light 217,010
AppShell With Mobile Nav probe dark 216,960
Collapsible Dividers probe dark 66,445
Collapsible Dividers probe light 66,445
AppShell Playground neutral dark 65,198
AppShell Playground neutral light 63,788
Chat Default neutral dark 36,304
Chat Default neutral light 35,767
Chat Empty State probe light 23,531
Chat Empty State probe dark 22,622
ChatAutoScroll Scroll Behavior Comparison neutral dark 15,378
ChatAutoScroll Scroll Behavior Comparison neutral light 14,107
Chat With Attachments probe light 13,406
Chat With Attachments probe dark 11,232

and 28 more.


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-1 to display-3 use the body family (TypeStyle.swift lines 20–22) where core uses the heading family, so Stone, Matcha and Chocolate show a different typeface on iOS than on the web.
  • textInitializersBuildTheSameProps, textColorDefaultsByTypeAsCoreDoes and headingInitializersBuildTheSameProps need @MainActor, because they call main-actor-isolated view members from nonisolated tests, which Swift 6 rejects.
  • justify has no effect on a one-line Heading (Heading.swift line 60), which core aligns across the heading's full width.
  • astryxLineLimit traps on an infinite or very large maxLines (TypeStyle.swift lines 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]

Comment on lines +20 to +22
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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +104 to +107
func astryxLineLimit(_ maxLines: Double?) -> Int? {
guard let maxLines, maxLines >= 1 else { return nil }
return Int(maxLines)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-1 to display-3 use the body family (TypeStyle.swift lines 20–22) where core uses the heading family, so Chocolate, Matcha and Stone show a different typeface on iOS than on the web.
  • textInitializersBuildTheSameProps, textColorDefaultsByTypeAsCoreDoes and headingInitializersBuildTheSameProps need @MainActor, because the package builds in Swift 6 mode, where calling a view's members from a nonisolated test does not compile.
  • justify has no effect on a one-line Heading (Heading.swift line 60), which core aligns across the container.
  • astryxLineLimit traps on an infinite or very large maxLines (TypeStyle.swift lines 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]

Comment on lines +20 to +22
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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +104 to +106
func astryxLineLimit(_ maxLines: Double?) -> Int? {
guard let maxLines, maxLines >= 1 else { return nil }
return Int(maxLines)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +72 to +76
} 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)))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@cixzhang
cixzhang changed the base branch from native/swift-core-names to main October 24, 2026 23:59
@cixzhang
cixzhang force-pushed the native/swift-text-heading-props branch from c7c537e to bd51b1b Compare October 25, 2026 00:01

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-1 to display-3 use the body family (TypeStyle.swift lines 20–22) where core uses the heading family, so Chocolate, Matcha and Stone show a different typeface on iOS than on the web.
  • justify has no effect on a one-line Heading (Heading.swift line 60), which core aligns across its container.
  • astryxLineLimit traps on an infinite or very large maxLines (TypeStyle.swift lines 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 maxLines unset, both views apply .lineLimit(nil) (Text.swift line 58, Heading.swift line 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))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 maxLines unset, both views apply .lineLimit(nil) (Text.swift line 58, Heading.swift line 59), which overrides a caller's own .lineLimit.
  • Text(type: .inherit, size:) switches to the body family while its doc comment says inherit keeps 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]

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]

Comment on lines +76 to +80
} 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)))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]

@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec ecf083c

@cixzhang
cixzhang merged commit f41fc05 into main Oct 25, 2026
71 checks passed
@github-actions
github-actions Bot deleted the native/swift-text-heading-props branch October 26, 2026 06:31

This branch was successfully deployed

1 active deployment
Preview — ecf083cc Deployed Oct 25, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant