Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

feat(native): Swift Button meets iOS 26 Liquid Glass in bars and floating containers (#9336)

Cindy Zhang38a27070e012
diff --git a/packages/native/apple/README.md b/packages/native/apple/README.md
index 2596830b88..f74abb542c 100644
--- a/packages/native/apple/README.md
+++ b/packages/native/apple/README.md
@@ -95,6 +95,13 @@ struct DemoApp: App {
core's default theme. Either way they follow Dark Mode and the person's text
size.
+On iOS and iPadOS 26 and later, a `Button` in a navigation bar or toolbar draws
+no fill of its own, so the bar's Liquid Glass shows, and `astryxFloating()` on
+a container of controls over scrolling content gives its Buttons the system's
+glass. A `variant` keeps its meaning in glass, and Reduce Transparency or
+Increase Contrast draws a solid token fill instead. Elsewhere, and on macOS,
+Buttons keep their token look.
+
## Theme tokens
Components read every color, size, and font from the `astryx` environment
diff --git a/packages/native/apple/Sources/Astryx/Button/Button.swift b/packages/native/apple/Sources/Astryx/Button/Button.swift
index 6f25cba836..9830a0b1a4 100644
--- a/packages/native/apple/Sources/Astryx/Button/Button.swift
+++ b/packages/native/apple/Sources/Astryx/Button/Button.swift
@@ -4,10 +4,17 @@
/// A labeled action, painted with the theme's tokens. It takes core's Button
/// props (`ButtonProps`). With `href` it is a link the system opens. The tap
/// area reaches the platform's 44-by-44-point minimum even when the drawn
-/// button is smaller.
+/// button is smaller. On iOS and iPadOS 26 and later, in a system bar or a
+/// container `astryxFloating()` marks, it draws the system's Liquid Glass in
+/// place of its own fill, keeping its variant's meaning.
public struct Button: View {
public let props: ButtonProps
@Environment(\.astryx) private var astryx
+ @Environment(\.astryxFloating) private var isFloating
+ @Environment(\.accessibilityReduceTransparency) private var reducesTransparency
+ @Environment(\.colorSchemeContrast) private var contrast
+ /// Whether a system bar hosts this Button, as its bar probe reports.
+ @State private var isInBar = false
/// Which part of a Button with `href` holds focus: its link, or the button
/// it draws while disabled.
enum Part: Hashable { case link, button }
@@ -87,8 +94,8 @@ public struct Button: View {
nonisolated static func safeDestination(_ href: String) -> String? { astryxSafeDestination(href) }
public var body: some View {
- control
- .buttonStyle(style)
+ styledControl
+ .background { barProbe }
// The shared Astryx tooltip on hover and keyboard focus, as core's
// Button tooltip; its words are the VoiceOver hint.
.astryxTooltip(props.tooltip, hint: props.tooltip, focus: .control)
@@ -156,6 +163,38 @@ public struct Button: View {
ProgressView().controlSize(.small).tint(foreground)
}
}
+ .modifier(SystemBarLabel(tint: systemBarTint, style: style))
+ }
+
+ /// The tint a primary or destructive Button in a bar gives the bar's
+ /// glass, through SwiftUI's prominent glass style (FR7, FR8); nil
+ /// elsewhere. It depends on placement and variant only, so disabling the
+ /// Button keeps one view structure and its focus (FR6).
+ var systemBarTint: Color? {
+ guard case .glass(.barProminent(let role)) = surface else { return nil }
+ return role.color(astryx.tokens)
+ }
+
+ /// The control in its style: SwiftUI's prominent glass in a bar for primary
+ /// and destructive, so the bar tints its own glass; the Astryx style
+ /// everywhere else.
+ @ViewBuilder private var styledControl: some View {
+ #if os(iOS) && compiler(>=6.2)
+ if #available(iOS 26, *), let tint = systemBarTint {
+ // The elevation paints beneath the system's capsule (FR11). Disabled,
+ // the whole control dims and takes no touch, so the style shows no
+ // press response, while it keeps its focus stop (FR6, FR11). The bar
+ // draws the capsule itself, so its tint dims as well.
+ control.buttonStyle(.glassProminent).tint(isDisabled ? tint.opacity(0.5) : tint)
+ .astryxShadow(shadow, in: Capsule())
+ .opacity(isDisabled ? 0.5 : 1)
+ .allowsHitTesting(!isDisabled)
+ } else {
+ control.buttonStyle(style)
+ }
+ #else
+ control.buttonStyle(style)
+ #endif
}
private var style: AstryxButtonStyle {
@@ -166,10 +205,38 @@ public struct Button: View {
foreground: foreground,
background: background,
shadow: shadow,
- isDimmed: isDisabled
+ isDimmed: isDisabled,
+ surface: surface
+ )
+ }
+
+ /// Where this Button sits: a bar wins over a floating container, so glass
+ /// never draws inside the bar's own glass.
+ var placement: ButtonPlacement {
+ isInBar ? .bar : isFloating ? .floating : .content
+ }
+
+ /// What draws behind the label (FR7–FR10, ORD2).
+ var surface: ButtonSurface {
+ ButtonSurface.resolve(
+ variant: props.variant,
+ placement: placement,
+ glassAvailable: ButtonSurface.glassAvailable,
+ prefersSolid: reducesTransparency || contrast == .increased
)
}
+ /// Finds a system bar hosting this Button, only where glass can draw.
+ @ViewBuilder private var barProbe: some View {
+ #if os(iOS)
+ if ButtonSurface.glassAvailable {
+ ButtonBarProbe { isInBar = $0 }
+ .frame(width: 0, height: 0)
+ .accessibilityHidden(true)
+ }
+ #endif
+ }
+
/// The button's accessible name: its label, also while loading.
var accessibilityText: String { props.label }
@@ -240,26 +307,142 @@ struct AstryxButtonStyle: ButtonStyle {
let shadow: [ShadowLayer]
/// Draws the disabled look for a disabled Button that keeps its focus stop.
var isDimmed = false
+ /// What draws behind the label: the token look unless the Button sits in
+ /// a bar or a floating container on iOS 26 (FR7–FR10).
+ var surface: ButtonSurface = .token
@Environment(\.isEnabled) private var environmentEnabled
private var isEnabled: Bool { environmentEnabled && !isDimmed }
func makeBody(configuration: Configuration) -> some View {
- let shape = RoundedRectangle(cornerRadius: astryx.tokens.radius.element, style: .continuous)
+ switch surface {
+ case .token:
+ tokenBody(configuration, fill: background, edge: nil, keepsTapMinimum: true)
+ case .solid(let role, let inBar):
+ // Drawn on the surface color, so a translucent token such as
+ // `color.neutral` reads as it does on a page, opaque over any content.
+ tokenBody(
+ configuration, fill: role.color(astryx.tokens), edge: astryx.tokens.color.borderEmphasized,
+ underlay: astryx.tokens.color.backgroundSurface, keepsTapMinimum: !inBar
+ )
+ case .glass(.barItem):
+ barItemBody(configuration, labelColor: foreground)
+ case .glass(.barProminent(let role)):
+ // Drawn through SwiftUI's prominent style wherever glass draws; this
+ // is only a fallback, the label in the variant's color on the bar.
+ barItemBody(configuration, labelColor: role.color(astryx.tokens))
+ case .glass(let glass):
+ glassBody(configuration, glass: glass)
+ }
+ }
+
+ private var shape: RoundedRectangle {
+ RoundedRectangle(cornerRadius: astryx.tokens.radius.element, style: .continuous)
+ }
+
+ /// The label in the theme's type, at least the size's height, which grows
+ /// with text size, but not so far that one line becomes a tall slab.
+ private func label(_ configuration: Configuration, padded: Bool, color: Color? = nil) -> some View {
let font = astryx.tokens.font
- configuration.label
+ return configuration.label
.font(astryx.font(TypeStyle(font.label, families: font.family.body)))
- .foregroundStyle(foreground)
- .padding(.horizontal, astryx.tokens.space.s3)
- // Grows with text size, but not so far that one line of a large label
- // becomes a tall slab.
+ .foregroundStyle(color ?? foreground)
+ .padding(.horizontal, padded ? astryx.tokens.space.s3 : 0)
.frame(maxWidth: fillsWidth ? .infinity : nil, minHeight: height * min(astryx.textScale, 1.4))
- .background(shape.fill(background))
- .astryxShadow(shadow, in: shape)
- .opacity(isEnabled ? (configuration.isPressed ? 0.75 : 1) : 0.5)
+ }
+
+ private func pressOpacity(_ configuration: Configuration) -> Double {
+ isEnabled ? (configuration.isPressed ? 0.75 : 1) : 0.5
+ }
+
+ /// The token look, and the solid fill with an edge (FR10).
+ @ViewBuilder
+ private func tokenBody(
+ _ configuration: Configuration, fill: Color, edge: Color?, underlay: Color? = nil, keepsTapMinimum: Bool
+ ) -> some View {
+ let drawn = label(configuration, padded: true)
+ .background(shape.fill(fill))
+ .background { if let underlay { shape.fill(underlay) } }
+ .overlay { if let edge { shape.strokeBorder(edge, lineWidth: astryx.tokens.size.borderWidth) } }
+ .astryxShadow(shadow, in: shape, borderWidth: edge == nil ? 0 : astryx.tokens.size.borderWidth)
+ .opacity(pressOpacity(configuration))
+ if keepsTapMinimum {
// Drawn at the token size; laid out at least 44 by 44 so the whole
// platform-minimum tap area counts.
- .frame(minWidth: 44, minHeight: 44)
+ drawn.frame(minWidth: 44, minHeight: 44).contentShape(Rectangle())
+ } else {
+ // In a bar, which may offer almost no width, the label stays whole
+ // (FR11).
+ drawn.fixedSize(horizontal: !fillsWidth, vertical: false).contentShape(Rectangle())
+ }
+ }
+
+ /// In a system bar: no fill or border, so the bar's glass is the only
+ /// chrome; no Astryx padding, so the label is never cut short in a bar with
+ /// room; a set elevation still paints its shadow (FR7, FR11).
+ private func barItemBody(_ configuration: Configuration, labelColor: Color) -> some View {
+ label(configuration, padded: false, color: labelColor)
+ .fixedSize(horizontal: !fillsWidth, vertical: false)
+ .astryxShadow(shadow, in: shape)
+ .opacity(pressOpacity(configuration))
.contentShape(Rectangle())
}
+
+ /// In a floating container: the system's glass in the token shape, tinted
+ /// for primary and destructive, with the elevation shadow beneath (FR8,
+ /// FR9, FR11).
+ @ViewBuilder
+ private func glassBody(_ configuration: Configuration, glass: ButtonGlass) -> some View {
+ #if os(iOS) && compiler(>=6.2)
+ if #available(iOS 26, *) {
+ label(configuration, padded: true)
+ .glassEffect(effect(glass), in: shape)
+ .astryxShadow(shadow, in: shape)
+ .opacity(isEnabled ? 1 : 0.5)
+ .frame(minWidth: 44, minHeight: 44)
+ .contentShape(Rectangle())
+ } else {
+ tokenBody(configuration, fill: background, edge: nil, keepsTapMinimum: true)
+ }
+ #else
+ tokenBody(configuration, fill: background, edge: nil, keepsTapMinimum: true)
+ #endif
+ }
+
+ #if os(iOS) && compiler(>=6.2)
+ @available(iOS 26, *)
+ private func effect(_ glass: ButtonGlass) -> Glass {
+ switch glass {
+ // A disabled Button keeps its focus stop but answers no touch with the
+ // glass's press effect, as the bar path draws it (FR11).
+ case .regular, .barItem, .barProminent: .regular.interactive(isEnabled)
+ case .clear: .clear.interactive(isEnabled)
+ case .prominent(let role): .regular.tint(role.color(astryx.tokens)).interactive(isEnabled)
+ }
+ }
+ #endif
}
+/// A label drawn by SwiftUI's own prominent glass style in a bar: the theme's
+/// type in the variant's label color, at least the size's height, kept whole
+/// or filling the width as `width` asks (FR11); the Astryx style draws all of
+/// this itself elsewhere.
+private struct SystemBarLabel: ViewModifier {
+ let tint: Color?
+ let style: AstryxButtonStyle
+
+ func body(content: Content) -> some View {
+ if tint != nil {
+ let font = style.astryx.tokens.font
+ content
+ .font(style.astryx.font(TypeStyle(font.label, families: font.family.body)))
+ .foregroundStyle(style.foreground)
+ .fixedSize(horizontal: !style.fillsWidth, vertical: false)
+ .frame(
+ maxWidth: style.fillsWidth ? .infinity : nil,
+ minHeight: style.height * min(style.astryx.textScale, 1.4)
+ )
+ } else {
+ content
+ }
+ }
+}
diff --git a/packages/native/apple/Sources/Astryx/Button/ButtonGlass.swift b/packages/native/apple/Sources/Astryx/Button/ButtonGlass.swift
new file mode 100644
index 0000000000..a459908ebf
--- /dev/null
+++ b/packages/native/apple/Sources/Astryx/Button/ButtonGlass.swift
@@ -0,0 +1,179 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+#if canImport(UIKit)
+import UIKit
+#endif
+
+/// Where a Button sits, which decides whether it meets the system's glass
+/// (FR7–FR9).
+enum ButtonPlacement: Sendable, Equatable {
+ /// In content: the token look.
+ case content
+ /// Hosted in a system bar, a navigation bar or a toolbar (FR7).
+ case bar
+ /// Inside a container `astryxFloating()` marks as floating (FR9).
+ case floating
+}
+
+/// A token color a glass tint or a solid fill takes (FR8, FR10).
+enum ButtonColorRole: Sendable, Equatable {
+ case accent, error, neutral, surface
+
+ func color(_ tokens: Tokens) -> Color {
+ switch self {
+ case .accent: tokens.color.accent
+ case .error: tokens.color.error
+ case .neutral: tokens.color.neutral
+ case .surface: tokens.color.backgroundSurface
+ }
+ }
+}
+
+/// The glass a Button draws in a bar or a floating container (FR8).
+enum ButtonGlass: Sendable, Equatable {
+ /// No surface of its own, so the bar's glass is its only chrome (FR7).
+ case barItem
+ /// The system's regular glass.
+ case regular
+ /// The system's clear glass, the least visible surface.
+ case clear
+ /// The system's glass, tinted with a token color.
+ case prominent(ButtonColorRole)
+ /// In a bar, the bar's own glass, tinted with a token color: SwiftUI's
+ /// prominent glass button style, so the bar tints its glass rather than
+ /// a second glass drawing inside it (FR7).
+ case barProminent(ButtonColorRole)
+}
+
+/// What a Button draws behind its label (FR7–FR10, ORD2).
+enum ButtonSurface: Sendable, Equatable {
+ /// The token look, in content, before iOS 26, and on macOS.
+ case token
+ /// The system's Liquid Glass (FR7–FR9).
+ case glass(ButtonGlass)
+ /// No glass under Reduce Transparency or Increase Contrast: the variant's
+ /// token fill with an emphasized edge (FR10). In a bar it keeps no
+ /// 44-point minimum of its own, since the bar sizes its items (FR11).
+ case solid(ButtonColorRole, inBar: Bool)
+
+ /// The surface for a variant where it sits (ORD2). An unset `variant` is
+ /// `secondary`, as in core. A set `variant` keeps its meaning: placement
+ /// picks its glass, never another variant's treatment (FR8). The theme's
+ /// `material` intent is not yet carried by `Theme.native`; absent, it keeps
+ /// FR7–FR9 (ORD2).
+ static func resolve(
+ variant: ButtonVariant?, placement: ButtonPlacement, glassAvailable: Bool, prefersSolid: Bool
+ ) -> ButtonSurface {
+ guard glassAvailable, placement != .content else { return .token }
+ let variant = variant ?? .secondary
+ if prefersSolid {
+ let role: ButtonColorRole = switch variant {
+ case .primary: .accent
+ case .destructive: .error
+ case .secondary: .neutral
+ case .ghost: .surface
+ }
+ return .solid(role, inBar: placement == .bar)
+ }
+ let inBar = placement == .bar
+ switch variant {
+ case .primary: return .glass(inBar ? .barProminent(.accent) : .prominent(.accent))
+ case .destructive: return .glass(inBar ? .barProminent(.error) : .prominent(.error))
+ case .secondary: return .glass(inBar ? .barItem : .regular)
+ case .ghost: return .glass(inBar ? .barItem : .clear)
+ }
+ }
+
+ /// Whether this platform draws Liquid Glass: iOS and iPadOS 26 and later,
+ /// built with an SDK that has it. macOS keeps the token look (FR10).
+ static var glassAvailable: Bool {
+ #if os(iOS) && compiler(>=6.2)
+ if #available(iOS 26, *) { return true }
+ #endif
+ return false
+ }
+}
+
+private struct AstryxFloatingKey: EnvironmentKey {
+ static let defaultValue = false
+}
+
+extension EnvironmentValues {
+ /// Whether `astryxFloating()` marks an enclosing container as floating.
+ var astryxFloating: Bool {
+ get { self[AstryxFloatingKey.self] }
+ set { self[AstryxFloatingKey.self] = newValue }
+ }
+}
+
+extension View {
+ /// Marks this container as floating over scrolling content, so the Astryx
+ /// Buttons inside it draw the system's Liquid Glass on iOS and iPadOS 26 and
+ /// later (`component:swift/Button` FR9). It only marks the container: it
+ /// changes no Button props, and elsewhere the Buttons keep their token look.
+ public func astryxFloating() -> some View {
+ environment(\.astryxFloating, true)
+ }
+}
+
+#if os(iOS)
+/// Tells a Button whether a system bar hosts it. SwiftUI has no public signal
+/// for this, so it looks among its UIKit ancestors for a navigation bar, a
+/// toolbar, or the host SwiftUI gives each bar item (on iOS 26 the bottom bar
+/// is a floating container, not a toolbar), checked whenever it moves or lays
+/// out. A bar, once found, holds: the bar re-hosts a prominent item where its
+/// ancestors no longer show the bar, and letting go would flip the Button
+/// back and forth. The host's name is not an API, so FR7's capture gate
+/// checks the navigation bar and the bottom bar on each new iOS.
+struct ButtonBarProbe: UIViewRepresentable {
+ let report: (Bool) -> Void
+
+ func makeUIView(context: Context) -> ProbeView {
+ let view = ProbeView()
+ view.report = report
+ view.isUserInteractionEnabled = false
+ view.isAccessibilityElement = false
+ return view
+ }
+
+ func updateUIView(_ view: ProbeView, context: Context) {
+ view.report = report
+ }
+
+ final class ProbeView: UIView {
+ var report: ((Bool) -> Void)?
+ private var found = false
+
+ override func didMoveToWindow() {
+ super.didMoveToWindow()
+ check()
+ }
+
+ override func didMoveToSuperview() {
+ super.didMoveToSuperview()
+ check()
+ }
+
+ override func layoutSubviews() {
+ super.layoutSubviews()
+ check()
+ }
+
+ private func check() {
+ guard !found else { return }
+ var node = superview
+ while let view = node {
+ if view is UINavigationBar || view is UIToolbar
+ || String(describing: type(of: view)).hasPrefix("UIKitBarItemHost") {
+ found = true
+ let report = report
+ // Reported after this layout pass, never during it.
+ Task { @MainActor in report?(true) }
+ return
+ }
+ node = view.superview
+ }
+ }
+ }
+}
+#endif
diff --git a/packages/native/apple/Tests/AstryxTests/ButtonGlassTests.swift b/packages/native/apple/Tests/AstryxTests/ButtonGlassTests.swift
new file mode 100644
index 0000000000..e11519f53b
--- /dev/null
+++ b/packages/native/apple/Tests/AstryxTests/ButtonGlassTests.swift
@@ -0,0 +1,149 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+import SwiftUI
+import Testing
+@testable import Astryx
+
+// A Swift Button meets the system's Liquid Glass in a bar or a floating
+// container on iOS and iPadOS 26, keeps its variant's meaning there, and draws
+// a solid token fill under Reduce Transparency or Increase Contrast
+// (component:swift/Button FR7–FR10, ORD2).
+
+private func surface(
+ _ variant: ButtonVariant?, _ placement: ButtonPlacement, solid: Bool = false, glass: Bool = true
+) -> ButtonSurface {
+ ButtonSurface.resolve(variant: variant, placement: placement, glassAvailable: glass, prefersSolid: solid)
+}
+
+@Test func everyVariantMapsToItsGlassInABarAndFloating() {
+ // FR8's table: a set variant keeps its meaning; only secondary and ghost
+ // share the bar's glass, and in a bar primary and destructive tint it.
+ #expect(surface(.primary, .bar) == .glass(.barProminent(.accent)))
+ #expect(surface(.primary, .floating) == .glass(.prominent(.accent)))
+ #expect(surface(.destructive, .bar) == .glass(.barProminent(.error)))
+ #expect(surface(.destructive, .floating) == .glass(.prominent(.error)))
+ #expect(surface(.secondary, .bar) == .glass(.barItem))
+ #expect(surface(.secondary, .floating) == .glass(.regular))
+ #expect(surface(.ghost, .bar) == .glass(.barItem))
+ #expect(surface(.ghost, .floating) == .glass(.clear))
+}
+
+@Test func anUnsetVariantIsSecondaryEverywhere() {
+ for placement in [ButtonPlacement.content, .bar, .floating] {
+ #expect(surface(nil, placement) == surface(.secondary, placement))
+ #expect(surface(nil, placement, solid: true) == surface(.secondary, placement, solid: true))
+ }
+}
+
+@Test func contentAndPlatformsWithoutGlassKeepTheTokenLook() {
+ for variant in ButtonVariant.allCases {
+ #expect(surface(variant, .content) == .token)
+ #expect(surface(variant, .bar, glass: false) == .token)
+ #expect(surface(variant, .floating, glass: false) == .token)
+ #expect(surface(variant, .bar, solid: true, glass: false) == .token)
+ }
+}
+
+@Test func reduceTransparencyOrIncreaseContrastDrawsTheVariantsSolidFill() {
+ // FR10: no glass, the variant's token fill, in a bar and floating.
+ let roles: [ButtonVariant: ButtonColorRole] = [
+ .primary: .accent, .destructive: .error, .secondary: .neutral, .ghost: .surface,
+ ]
+ for (variant, role) in roles {
+ #expect(surface(variant, .bar, solid: true) == .solid(role, inBar: true))
+ #expect(surface(variant, .floating, solid: true) == .solid(role, inBar: false))
+ }
+}
+
+@MainActor
+@Test func astryxFloatingOnlyMarksTheContainer() {
+ // FR9: the modifier changes no ButtonProps, only the environment.
+ var seen: [Bool] = []
+ let probe = EnvironmentReader { seen.append($0.astryxFloating) }
+ _ = Pixels(probe.frame(width: 4, height: 4))
+ _ = Pixels(probe.astryxFloating().frame(width: 4, height: 4))
+ #expect(seen.first == false)
+ #expect(seen.last == true)
+
+ let button = Astryx.Button(label: "New", variant: .primary) {}
+ let floating = Astryx.Button(label: "New", variant: .primary) {}
+ _ = floating.astryxFloating()
+ #expect(button.props.label == floating.props.label)
+ #expect(button.props.variant == floating.props.variant)
+}
+
+@MainActor
+@Test func aBarButtonDrawsNoFillOrPadding() {
+ // FR7, FR11: the bar's glass is the only chrome, and no Astryx padding
+ // can cut the label short.
+ let accent = Theme.default.light.color.accent
+ let barItem = Pixels(barStyled(surface: .glass(.barItem), background: accent))
+ let token = Pixels(barStyled(surface: .token, background: accent))
+ // The bar item draws nothing above its label; the token look fills its
+ // padding beside the label (it sits centered in its 44-point tap frame).
+ #expect(barItem.at(barItem.width / 2, 1)[3] == 0)
+ #expect(close(token.at(8, token.height / 2), rgba(accent)))
+ #expect(barItem.width < token.width)
+}
+
+@MainActor
+@Test func theProminentBarFallbackDrawsALabelInItsVariantsColor() {
+ // Where SwiftUI's prominent glass style is unavailable, a primary bar
+ // Button draws no fill and keeps primary's accent in its label; disabled,
+ // it dims.
+ let accent = rgba(Theme.default.light.color.accent)
+ let drawn = Pixels(barStyled(surface: .glass(.barProminent(.accent)), isDimmed: true))
+ #expect(drawn.at(drawn.width / 2, 1)[3] == 0)
+ // Pixels are premultiplied: a glyph pixel's color over its alpha is the
+ // label's color, and half opacity caps its alpha.
+ #expect(drawn.contains { p in
+ p[3] > 40 && (1...2).allSatisfy { abs(p[$0] * 255 / p[3] - accent[$0]) <= 24 }
+ })
+ #expect(!drawn.contains { $0[3] > 140 })
+}
+
+@MainActor
+@Test func aSolidFallbackDrawsTheFillWithAnEmphasizedEdge() {
+ let tokens = Theme.default.light
+ let solid = Pixels(barStyled(surface: .solid(.surface, inBar: false)))
+ #expect(close(solid.at(0, solid.height / 2), rgba(tokens.color.borderEmphasized)))
+ #expect(close(solid.at(8, solid.height / 2), rgba(tokens.color.backgroundSurface)))
+}
+
+@MainActor
+@Test func aSolidNeutralFillIsOpaqueOverContent() {
+ // FR10's solid fill hides what is behind it: the translucent neutral token
+ // draws on the surface color, as it reads on a page.
+ let solid = Pixels(barStyled(surface: .solid(.neutral, inBar: false)).background(Color.black))
+ let pixel = solid.at(8, solid.height / 2)
+ // The light surface, tinted by neutral, not the black content behind it.
+ #expect(pixel[3] == 255)
+ #expect(pixel[0...2].allSatisfy { $0 > 200 })
+}
+
+/// A Button's style drawn alone at a given surface.
+@MainActor
+private func barStyled(
+ surface: ButtonSurface, background: Color? = nil, isDimmed: Bool = false
+) -> some View {
+ let astryx = EnvironmentValues().astryx
+ return SwiftUI.Button("Share") {}
+ .buttonStyle(
+ AstryxButtonStyle(
+ astryx: astryx, height: astryx.tokens.size.elementMd, fillsWidth: false,
+ foreground: astryx.tokens.color.textPrimary,
+ background: background ?? astryx.tokens.color.neutral, shadow: [], isDimmed: isDimmed, surface: surface
+ )
+ )
+ .fixedSize()
+}
+
+/// Reports the environment it is drawn in.
+private struct EnvironmentReader: View {
+ let read: (EnvironmentValues) -> Void
+ @Environment(\.self) private var environment
+ var body: some View {
+ read(environment)
+ return Color.clear
+ }
+}