Skip to content

feat(native): Button width projects to content or fill on native platforms - #8305

Merged
cixzhang merged 1 commit into
mainfrom
native/button-width-projection
Oct 24, 2026
Merged

cixzhang merged 1 commit into
mainfrom
native/button-width-projection

Conversation

@cixzhang

Copy link
Copy Markdown
Contributor

What changes for people

An iOS developer can ask for a full-width button the way core does, width: .fill, instead of a Swift-only spelling. A logic core sends the same value on the wire. Other web widths (a pixel number, a percentage other than 100%) stay web-only, so a native type never receives a width it cannot draw.

What this does

Applies AST-082 FR4's projected-prop rule to Button width, as the owner decided (portable closed form content | fill):

  • NativeAdditions.projections names a prop whose web type is wider than a portable kind, with each portable value mapped to the one web value it means. Button declares width: {content: 'auto', fill: '100%'}; content is the default.
  • fromComponentDoc puts a projected prop in the core as a closed set of those values, documents the mapping on the prop, and records it on the contract (projections). Without a projection the prop stays in the web contract, as before.
  • Generated Swift: ButtonWidth (content, fill), and width on ButtonProps and ButtonNode for iOS and macOS. The TypeScript native types get width?: 'content' | 'fill'.

The Swift Button view adopts width when it moves onto ButtonProps, in a following pull request; until then it keeps its interim fillsWidth.

Testing

  • pnpm vitest run --project node packages/native/src/contract: a projected prop enters the core at its portable values with distinct web values; the same prop without a projection stays web-only; core's Button contract has width as content | fill mapped to 'auto' and '100%'.
  • pnpm -F @astryxdesign/native typecheck passes; swiftc -typecheck of both Swift modules, the tests, and the templates 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 24, 2026 9:35pm UTC

Request Review

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

astracat-bot Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Oct 24, 2026, 10:00 PM UTC

@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

46 of 504 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
Collapsible Dividers probe dark 66,445
Collapsible Dividers probe light 66,445
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
ProgressBar With Target Mark probe dark 7,895
ProgressBar With Target Mark probe light 7,895
Markdown Default neutral dark 7,573
Markdown Default neutral light 7,566

and 26 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.

No changes requested: Button width projects to content or fill exactly as AST-082 FR4 describes, the generated native TypeScript types accept only those two values, and the Swift binding builds and passes its tests on macOS and the iOS simulator. Nothing more is needed in this pull request; the visible full-width behavior on Apple platforms arrives when the Swift Button view moves onto ButtonProps and replaces fillsWidth, as the description plans.

[Automated review]

});
expect(sized.webOnly).toEqual([]);
const webValues = Object.values(sized.projections?.width ?? {});
expect(new Set(webValues).size).toBe(webValues.length);

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.

Non-blocking: this compares the fixture's own two web values, and fromComponentDoc stores that same object without checking distinctness, so the assertion passes even if no projection is recorded (webValues is then empty). The Button assertion in contracts.test.ts already proves the mapping; consider dropping this line or asserting something fromComponentDoc enforces.

@cixzhang
cixzhang merged commit 585c603 into main Oct 24, 2026
70 checks passed
@github-actions
github-actions Bot deleted the native/button-width-projection branch October 25, 2026 06:20
cixzhang added a commit that referenced this pull request Oct 30, 2026
… tokens (#8310)

## What changes for people

An iOS developer gets core's whole Button:

- `width: .fill` for a full-width button;
- `href`, which makes the button a real link the system opens and VoiceOver reads as a link;
- `tooltip` as a pointer tip and a VoiceOver hint;
- `elevation` drawn with the theme's shadow;
- `isInterruptible`, so a loading button can still be pressed to interrupt it.

With this, every Swift view that has a core contract takes its generated props, and every view reads the theme through typed tokens. The Login template's Sign in button fills its card through `width: .fill`, as on the web.

## What this does

- `Button` takes the generated `ButtonProps` (AST-093 FR5; Swift component API A2, A3, A4): a labeled initializer with the press last as a trailing closure (`onClick`), and the props initializer.
- Each prop follows core:
  - `href` on an enabled button draws a SwiftUI `Link` styled with the Astryx button style; a disabled one stays a disabled button.
  - A loading link stays a link, focusable and busy, and opens nothing until loading ends unless it is interruptible. The open goes through SwiftUI's `openURL`, so `onClick` runs on every activation: tap, VoiceOver, or keyboard.
  - `tooltip` is SwiftUI's `.help`: a hover tip with a pointer and a hint VoiceOver reads; a tap belongs to the button, as with core's `touchTrigger: auto`.
  - `elevation` draws the theme's shadow; `width` is `content` or `fill`; `size` and `variant` come from typed tokens.
- `AstryxNodeView` also draws Button and TextInput nodes.
- **G9:**
  - Banner and the Login template read typed tokens.
  - The by-name lookups (`astryx.color("…")`, `size`, `space`, `fontSize`, `font(size:…)`) are no longer public.
- **New spec record, `component:swift/Button`** (`packages/native/apple/Sources/Astryx/Button/Button.spec.md`, draft), per Cindy's decision that the loading rule belongs on the Swift Button spec. FR4 holds the loading-link rule: a loading Button with `href` stays a `Link`, keeps focus, shows its spinner, reads as busy, and does not open its destination until loading ends, unless the Button is interruptible, in which case each activation opens it. It never swaps to a button while busy (core Button FR9 and FR11). FR1–FR3 record the initializers, the loading presentation, and enabled or disabled `href`; FR5 says a script URL (`javascript:`, `vbscript:`) or an HTML document in a `data:` URL never opens, and the Button stays an enabled button. FR6: every disabled Button keeps its keyboard focus stop and shows its tooltip on focus, draws dimmed, reads as a dimmed button, and never runs `onClick` (core Button FR10, buttons family FR3); the focus stop is not measured until an app-hosted test can observe it. Each has a verification row. The record names the Apple guideline pages it follows (Buttons, Progress indicators, Accessibility) and the theme values Button reads. The shared component API record keeps no loading rule, only a pointer to Button FR4, and states no general rule. Theme environment's Current state describes the `Astryx` product.
- README: the interim-exemption list is gone; Banner, which has no native contract yet, is the one view with hand-written parameters.

**Landing order:** after #8307 (Card) and #8308 (TextInput); #8305 (Button `width`) is on `main`. This branch carries #8308's commit so it builds; it is rebased onto `main` as each lands, leaving only its own change (8 files).

- `tooltip` shows through the shared Astryx tooltip on hover and keyboard focus, its words the VoiceOver hint; no view uses `.help`.

**Compatibility:** breaking for canary callers. `action:`, `fillsWidth:`, `icon:`, and the hand-written `AstryxButtonVariant` and `AstryxButtonSize` give way to the generated `ButtonProps` (`onClick:`, `width:`, `ButtonVariant`, `ButtonSize`); the record states it.

## Writing rubric results

- R1 present tense: `component:swift/Button` and the component API pointer describe the system as it is.
- R2 research in the record: none.
- R3 evidence naming a change: none. Verification rows name tests, not pull requests.
- R4 rejected alternatives: none.
- R5 user impact first: the record's End-user impact row leads with a width that holds and a link that stays a link.
- R6 open questions: none.

## Captures (AST-093 FR5)

Capture set: iPhone 16 simulator, iOS 18.5, Xcode 16.4, built from this PR's head (`6cad853`). Each capture shows each variant and size, loading and disabled, full width, `href` as a link, loading and disabled links, each elevation, and two themes.

| Light | Dark | Light, largest text | Light, largest text, end | Dark, largest text | Dark, largest text, end |
|---|---|---|---|---|---|
| <img src="https://raw.githubusercontent.com/cixzhang/astryx-pixel-gallery/27f10ad1a94648b64447aba2a1ec79bfe79c13c3/pr-shots/8310/Button-light-large.png" width="150" alt="Button, Light"> | <img src="https://raw.githubusercontent.com/cixzhang/astryx-pixel-gallery/27f10ad1a94648b64447aba2a1ec79bfe79c13c3/pr-shots/8310/Button-dark-large.png" width="150" alt="Button, Dark"> | <img src="https://raw.githubusercontent.com/cixzhang/astryx-pixel-gallery/27f10ad1a94648b64447aba2a1ec79bfe79c13c3/pr-shots/8310/Button-light-ax5.png" width="150" alt="Button, Light, largest text"> | <img src="https://raw.githubusercontent.com/cixzhang/astryx-pixel-gallery/27f10ad1a94648b64447aba2a1ec79bfe79c13c3/pr-shots/8310/Button-light-ax5-end.png" width="150" alt="Button, Light, largest text, end"> | <img src="https://raw.githubusercontent.com/cixzhang/astryx-pixel-gallery/27f10ad1a94648b64447aba2a1ec79bfe79c13c3/pr-shots/8310/Button-dark-ax5.png" width="150" alt="Button, Dark, largest text"> | <img src="https://raw.githubusercontent.com/cixzhang/astryx-pixel-gallery/27f10ad1a94648b64447aba2a1ec79bfe79c13c3/pr-shots/8310/Button-dark-ax5-end.png" width="150" alt="Button, Dark, largest text, end"> |

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

**Banner** (statuses; two themes):

<img src="https://raw.githubusercontent.com/cixzhang/astryx-pixel-gallery/27f10ad1a94648b64447aba2a1ec79bfe79c13c3/pr-shots/8310/Banner-light-large.png" width="150"> <img src="https://raw.githubusercontent.com/cixzhang/astryx-pixel-gallery/27f10ad1a94648b64447aba2a1ec79bfe79c13c3/pr-shots/8310/Banner-dark-large.png" width="150"> <img src="https://raw.githubusercontent.com/cixzhang/astryx-pixel-gallery/27f10ad1a94648b64447aba2a1ec79bfe79c13c3/pr-shots/8310/Banner-light-ax5.png" width="150"> <img src="https://raw.githubusercontent.com/cixzhang/astryx-pixel-gallery/27f10ad1a94648b64447aba2a1ec79bfe79c13c3/pr-shots/8310/Banner-dark-ax5.png" width="150">

## Testing

- Swift tests:
  - both initializers build the same props;
  - an interruptible loading button takes presses, and a plain loading one does not;
  - `href` makes an enabled button a link and a disabled one a button;
  - a loading link stays a link and accepts no press, and an interruptible loading link opens;
  - every disabled Button keeps its focus stop and takes no press;
  - `javascript:`, `vbscript:`, and `data:text/html` destinations never open and leave an enabled button, while `data:image` and `mailto:` still open;
  - `fill` takes the whole width, in pixels;
  - elevation reads the theme's shadows;
  - Banner's typed colors;
  - the existing loading, disabled, 44-point, and Dynamic Type tests.
- `swiftc -typecheck` of both modules, the tests, and the templates passes; the Swift tests run in CI on the iOS Simulator.

Every changed file is under `packages/native/`.

This branch was successfully deployed

1 active deployment
Preview — 530fbf1f Deployed Oct 24, 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