@astryxdesign/native 0.7.12-canary.07e325e → 0.7.12-canary.0840fcc

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/apple/README.md CHANGED
@@ -95,6 +95,13 @@ struct DemoApp: App {
95
95
  core's default theme. Either way they follow Dark Mode and the person's text
96
96
  size.
97
97
 
98
+ On iOS and iPadOS 26 and later, a `Button` in a navigation bar or toolbar draws
99
+ no fill of its own, so the bar's Liquid Glass shows, and `astryxFloating()` on
100
+ a container of controls over scrolling content gives its Buttons the system's
101
+ glass. A `variant` keeps its meaning in glass, and Reduce Transparency or
102
+ Increase Contrast draws a solid token fill instead. Elsewhere, and on macOS,
103
+ Buttons keep their token look.
104
+
98
105
  ## Theme tokens
99
106
 
100
107
  Components read every color, size, and font from the `astryx` environment
@@ -4,10 +4,17 @@
4
4
  /// A labeled action, painted with the theme's tokens. It takes core's Button
5
5
  /// props (`ButtonProps`). With `href` it is a link the system opens. The tap
6
6
  /// area reaches the platform's 44-by-44-point minimum even when the drawn
7
- /// button is smaller.
7
+ /// button is smaller. On iOS and iPadOS 26 and later, in a system bar or a
8
+ /// container `astryxFloating()` marks, it draws the system's Liquid Glass in
9
+ /// place of its own fill, keeping its variant's meaning.
8
10
  public struct Button: View {
9
11
  public let props: ButtonProps
10
12
  @Environment(\.astryx) private var astryx
13
+ @Environment(\.astryxFloating) private var isFloating
14
+ @Environment(\.accessibilityReduceTransparency) private var reducesTransparency
15
+ @Environment(\.colorSchemeContrast) private var contrast
16
+ /// Whether a system bar hosts this Button, as its bar probe reports.
17
+ @State private var isInBar = false
11
18
  /// Which part of a Button with `href` holds focus: its link, or the button
12
19
  /// it draws while disabled.
13
20
  enum Part: Hashable { case link, button }
@@ -87,8 +94,8 @@ public struct Button: View {
87
94
  nonisolated static func safeDestination(_ href: String) -> String? { astryxSafeDestination(href) }
88
95
 
89
96
  public var body: some View {
90
- control
91
- .buttonStyle(style)
97
+ styledControl
98
+ .background { barProbe }
92
99
  // The shared Astryx tooltip on hover and keyboard focus, as core's
93
100
  // Button tooltip; its words are the VoiceOver hint.
94
101
  .astryxTooltip(props.tooltip, hint: props.tooltip, focus: .control)
@@ -156,6 +163,38 @@ public struct Button: View {
156
163
  ProgressView().controlSize(.small).tint(foreground)
157
164
  }
158
165
  }
166
+ .modifier(SystemBarLabel(tint: systemBarTint, style: style))
167
+ }
168
+
169
+ /// The tint a primary or destructive Button in a bar gives the bar's
170
+ /// glass, through SwiftUI's prominent glass style (FR7, FR8); nil
171
+ /// elsewhere. It depends on placement and variant only, so disabling the
172
+ /// Button keeps one view structure and its focus (FR6).
173
+ var systemBarTint: Color? {
174
+ guard case .glass(.barProminent(let role)) = surface else { return nil }
175
+ return role.color(astryx.tokens)
176
+ }
177
+
178
+ /// The control in its style: SwiftUI's prominent glass in a bar for primary
179
+ /// and destructive, so the bar tints its own glass; the Astryx style
180
+ /// everywhere else.
181
+ @ViewBuilder private var styledControl: some View {
182
+ #if os(iOS) && compiler(>=6.2)
183
+ if #available(iOS 26, *), let tint = systemBarTint {
184
+ // The elevation paints beneath the system's capsule (FR11). Disabled,
185
+ // the whole control dims and takes no touch, so the style shows no
186
+ // press response, while it keeps its focus stop (FR6, FR11). The bar
187
+ // draws the capsule itself, so its tint dims as well.
188
+ control.buttonStyle(.glassProminent).tint(isDisabled ? tint.opacity(0.5) : tint)
189
+ .astryxShadow(shadow, in: Capsule())
190
+ .opacity(isDisabled ? 0.5 : 1)
191
+ .allowsHitTesting(!isDisabled)
192
+ } else {
193
+ control.buttonStyle(style)
194
+ }
195
+ #else
196
+ control.buttonStyle(style)
197
+ #endif
159
198
  }
160
199
 
161
200
  private var style: AstryxButtonStyle {
@@ -166,10 +205,38 @@ public struct Button: View {
166
205
  foreground: foreground,
167
206
  background: background,
168
207
  shadow: shadow,
169
- isDimmed: isDisabled
208
+ isDimmed: isDisabled,
209
+ surface: surface
210
+ )
211
+ }
212
+
213
+ /// Where this Button sits: a bar wins over a floating container, so glass
214
+ /// never draws inside the bar's own glass.
215
+ var placement: ButtonPlacement {
216
+ isInBar ? .bar : isFloating ? .floating : .content
217
+ }
218
+
219
+ /// What draws behind the label (FR7–FR10, ORD2).
220
+ var surface: ButtonSurface {
221
+ ButtonSurface.resolve(
222
+ variant: props.variant,
223
+ placement: placement,
224
+ glassAvailable: ButtonSurface.glassAvailable,
225
+ prefersSolid: reducesTransparency || contrast == .increased
170
226
  )
171
227
  }
172
228
 
229
+ /// Finds a system bar hosting this Button, only where glass can draw.
230
+ @ViewBuilder private var barProbe: some View {
231
+ #if os(iOS)
232
+ if ButtonSurface.glassAvailable {
233
+ ButtonBarProbe { isInBar = $0 }
234
+ .frame(width: 0, height: 0)
235
+ .accessibilityHidden(true)
236
+ }
237
+ #endif
238
+ }
239
+
173
240
  /// The button's accessible name: its label, also while loading.
174
241
  var accessibilityText: String { props.label }
175
242
 
@@ -240,26 +307,142 @@ struct AstryxButtonStyle: ButtonStyle {
240
307
  let shadow: [ShadowLayer]
241
308
  /// Draws the disabled look for a disabled Button that keeps its focus stop.
242
309
  var isDimmed = false
310
+ /// What draws behind the label: the token look unless the Button sits in
311
+ /// a bar or a floating container on iOS 26 (FR7–FR10).
312
+ var surface: ButtonSurface = .token
243
313
  @Environment(\.isEnabled) private var environmentEnabled
244
314
  private var isEnabled: Bool { environmentEnabled && !isDimmed }
245
315
 
246
316
  func makeBody(configuration: Configuration) -> some View {
247
- let shape = RoundedRectangle(cornerRadius: astryx.tokens.radius.element, style: .continuous)
317
+ switch surface {
318
+ case .token:
319
+ tokenBody(configuration, fill: background, edge: nil, keepsTapMinimum: true)
320
+ case .solid(let role, let inBar):
321
+ // Drawn on the surface color, so a translucent token such as
322
+ // `color.neutral` reads as it does on a page, opaque over any content.
323
+ tokenBody(
324
+ configuration, fill: role.color(astryx.tokens), edge: astryx.tokens.color.borderEmphasized,
325
+ underlay: astryx.tokens.color.backgroundSurface, keepsTapMinimum: !inBar
326
+ )
327
+ case .glass(.barItem):
328
+ barItemBody(configuration, labelColor: foreground)
329
+ case .glass(.barProminent(let role)):
330
+ // Drawn through SwiftUI's prominent style wherever glass draws; this
331
+ // is only a fallback, the label in the variant's color on the bar.
332
+ barItemBody(configuration, labelColor: role.color(astryx.tokens))
333
+ case .glass(let glass):
334
+ glassBody(configuration, glass: glass)
335
+ }
336
+ }
337
+
338
+ private var shape: RoundedRectangle {
339
+ RoundedRectangle(cornerRadius: astryx.tokens.radius.element, style: .continuous)
340
+ }
341
+
342
+ /// The label in the theme's type, at least the size's height, which grows
343
+ /// with text size, but not so far that one line becomes a tall slab.
344
+ private func label(_ configuration: Configuration, padded: Bool, color: Color? = nil) -> some View {
248
345
  let font = astryx.tokens.font
249
- configuration.label
346
+ return configuration.label
250
347
  .font(astryx.font(TypeStyle(font.label, families: font.family.body)))
251
- .foregroundStyle(foreground)
252
- .padding(.horizontal, astryx.tokens.space.s3)
253
- // Grows with text size, but not so far that one line of a large label
254
- // becomes a tall slab.
348
+ .foregroundStyle(color ?? foreground)
349
+ .padding(.horizontal, padded ? astryx.tokens.space.s3 : 0)
255
350
  .frame(maxWidth: fillsWidth ? .infinity : nil, minHeight: height * min(astryx.textScale, 1.4))
256
- .background(shape.fill(background))
257
- .astryxShadow(shadow, in: shape)
258
- .opacity(isEnabled ? (configuration.isPressed ? 0.75 : 1) : 0.5)
351
+ }
352
+
353
+ private func pressOpacity(_ configuration: Configuration) -> Double {
354
+ isEnabled ? (configuration.isPressed ? 0.75 : 1) : 0.5
355
+ }
356
+
357
+ /// The token look, and the solid fill with an edge (FR10).
358
+ @ViewBuilder
359
+ private func tokenBody(
360
+ _ configuration: Configuration, fill: Color, edge: Color?, underlay: Color? = nil, keepsTapMinimum: Bool
361
+ ) -> some View {
362
+ let drawn = label(configuration, padded: true)
363
+ .background(shape.fill(fill))
364
+ .background { if let underlay { shape.fill(underlay) } }
365
+ .overlay { if let edge { shape.strokeBorder(edge, lineWidth: astryx.tokens.size.borderWidth) } }
366
+ .astryxShadow(shadow, in: shape, borderWidth: edge == nil ? 0 : astryx.tokens.size.borderWidth)
367
+ .opacity(pressOpacity(configuration))
368
+ if keepsTapMinimum {
259
369
  // Drawn at the token size; laid out at least 44 by 44 so the whole
260
370
  // platform-minimum tap area counts.
261
- .frame(minWidth: 44, minHeight: 44)
371
+ drawn.frame(minWidth: 44, minHeight: 44).contentShape(Rectangle())
372
+ } else {
373
+ // In a bar, which may offer almost no width, the label stays whole
374
+ // (FR11).
375
+ drawn.fixedSize(horizontal: !fillsWidth, vertical: false).contentShape(Rectangle())
376
+ }
377
+ }
378
+
379
+ /// In a system bar: no fill or border, so the bar's glass is the only
380
+ /// chrome; no Astryx padding, so the label is never cut short in a bar with
381
+ /// room; a set elevation still paints its shadow (FR7, FR11).
382
+ private func barItemBody(_ configuration: Configuration, labelColor: Color) -> some View {
383
+ label(configuration, padded: false, color: labelColor)
384
+ .fixedSize(horizontal: !fillsWidth, vertical: false)
385
+ .astryxShadow(shadow, in: shape)
386
+ .opacity(pressOpacity(configuration))
262
387
  .contentShape(Rectangle())
263
388
  }
389
+
390
+ /// In a floating container: the system's glass in the token shape, tinted
391
+ /// for primary and destructive, with the elevation shadow beneath (FR8,
392
+ /// FR9, FR11).
393
+ @ViewBuilder
394
+ private func glassBody(_ configuration: Configuration, glass: ButtonGlass) -> some View {
395
+ #if os(iOS) && compiler(>=6.2)
396
+ if #available(iOS 26, *) {
397
+ label(configuration, padded: true)
398
+ .glassEffect(effect(glass), in: shape)
399
+ .astryxShadow(shadow, in: shape)
400
+ .opacity(isEnabled ? 1 : 0.5)
401
+ .frame(minWidth: 44, minHeight: 44)
402
+ .contentShape(Rectangle())
403
+ } else {
404
+ tokenBody(configuration, fill: background, edge: nil, keepsTapMinimum: true)
405
+ }
406
+ #else
407
+ tokenBody(configuration, fill: background, edge: nil, keepsTapMinimum: true)
408
+ #endif
409
+ }
410
+
411
+ #if os(iOS) && compiler(>=6.2)
412
+ @available(iOS 26, *)
413
+ private func effect(_ glass: ButtonGlass) -> Glass {
414
+ switch glass {
415
+ // A disabled Button keeps its focus stop but answers no touch with the
416
+ // glass's press effect, as the bar path draws it (FR11).
417
+ case .regular, .barItem, .barProminent: .regular.interactive(isEnabled)
418
+ case .clear: .clear.interactive(isEnabled)
419
+ case .prominent(let role): .regular.tint(role.color(astryx.tokens)).interactive(isEnabled)
420
+ }
421
+ }
422
+ #endif
264
423
  }
265
424
 
425
+ /// A label drawn by SwiftUI's own prominent glass style in a bar: the theme's
426
+ /// type in the variant's label color, at least the size's height, kept whole
427
+ /// or filling the width as `width` asks (FR11); the Astryx style draws all of
428
+ /// this itself elsewhere.
429
+ private struct SystemBarLabel: ViewModifier {
430
+ let tint: Color?
431
+ let style: AstryxButtonStyle
432
+
433
+ func body(content: Content) -> some View {
434
+ if tint != nil {
435
+ let font = style.astryx.tokens.font
436
+ content
437
+ .font(style.astryx.font(TypeStyle(font.label, families: font.family.body)))
438
+ .foregroundStyle(style.foreground)
439
+ .fixedSize(horizontal: !style.fillsWidth, vertical: false)
440
+ .frame(
441
+ maxWidth: style.fillsWidth ? .infinity : nil,
442
+ minHeight: style.height * min(style.astryx.textScale, 1.4)
443
+ )
444
+ } else {
445
+ content
446
+ }
447
+ }
448
+ }
@@ -0,0 +1,179 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ #if canImport(UIKit)
4
+ import UIKit
5
+ #endif
6
+
7
+ /// Where a Button sits, which decides whether it meets the system's glass
8
+ /// (FR7–FR9).
9
+ enum ButtonPlacement: Sendable, Equatable {
10
+ /// In content: the token look.
11
+ case content
12
+ /// Hosted in a system bar, a navigation bar or a toolbar (FR7).
13
+ case bar
14
+ /// Inside a container `astryxFloating()` marks as floating (FR9).
15
+ case floating
16
+ }
17
+
18
+ /// A token color a glass tint or a solid fill takes (FR8, FR10).
19
+ enum ButtonColorRole: Sendable, Equatable {
20
+ case accent, error, neutral, surface
21
+
22
+ func color(_ tokens: Tokens) -> Color {
23
+ switch self {
24
+ case .accent: tokens.color.accent
25
+ case .error: tokens.color.error
26
+ case .neutral: tokens.color.neutral
27
+ case .surface: tokens.color.backgroundSurface
28
+ }
29
+ }
30
+ }
31
+
32
+ /// The glass a Button draws in a bar or a floating container (FR8).
33
+ enum ButtonGlass: Sendable, Equatable {
34
+ /// No surface of its own, so the bar's glass is its only chrome (FR7).
35
+ case barItem
36
+ /// The system's regular glass.
37
+ case regular
38
+ /// The system's clear glass, the least visible surface.
39
+ case clear
40
+ /// The system's glass, tinted with a token color.
41
+ case prominent(ButtonColorRole)
42
+ /// In a bar, the bar's own glass, tinted with a token color: SwiftUI's
43
+ /// prominent glass button style, so the bar tints its glass rather than
44
+ /// a second glass drawing inside it (FR7).
45
+ case barProminent(ButtonColorRole)
46
+ }
47
+
48
+ /// What a Button draws behind its label (FR7–FR10, ORD2).
49
+ enum ButtonSurface: Sendable, Equatable {
50
+ /// The token look, in content, before iOS 26, and on macOS.
51
+ case token
52
+ /// The system's Liquid Glass (FR7–FR9).
53
+ case glass(ButtonGlass)
54
+ /// No glass under Reduce Transparency or Increase Contrast: the variant's
55
+ /// token fill with an emphasized edge (FR10). In a bar it keeps no
56
+ /// 44-point minimum of its own, since the bar sizes its items (FR11).
57
+ case solid(ButtonColorRole, inBar: Bool)
58
+
59
+ /// The surface for a variant where it sits (ORD2). An unset `variant` is
60
+ /// `secondary`, as in core. A set `variant` keeps its meaning: placement
61
+ /// picks its glass, never another variant's treatment (FR8). The theme's
62
+ /// `material` intent is not yet carried by `Theme.native`; absent, it keeps
63
+ /// FR7–FR9 (ORD2).
64
+ static func resolve(
65
+ variant: ButtonVariant?, placement: ButtonPlacement, glassAvailable: Bool, prefersSolid: Bool
66
+ ) -> ButtonSurface {
67
+ guard glassAvailable, placement != .content else { return .token }
68
+ let variant = variant ?? .secondary
69
+ if prefersSolid {
70
+ let role: ButtonColorRole = switch variant {
71
+ case .primary: .accent
72
+ case .destructive: .error
73
+ case .secondary: .neutral
74
+ case .ghost: .surface
75
+ }
76
+ return .solid(role, inBar: placement == .bar)
77
+ }
78
+ let inBar = placement == .bar
79
+ switch variant {
80
+ case .primary: return .glass(inBar ? .barProminent(.accent) : .prominent(.accent))
81
+ case .destructive: return .glass(inBar ? .barProminent(.error) : .prominent(.error))
82
+ case .secondary: return .glass(inBar ? .barItem : .regular)
83
+ case .ghost: return .glass(inBar ? .barItem : .clear)
84
+ }
85
+ }
86
+
87
+ /// Whether this platform draws Liquid Glass: iOS and iPadOS 26 and later,
88
+ /// built with an SDK that has it. macOS keeps the token look (FR10).
89
+ static var glassAvailable: Bool {
90
+ #if os(iOS) && compiler(>=6.2)
91
+ if #available(iOS 26, *) { return true }
92
+ #endif
93
+ return false
94
+ }
95
+ }
96
+
97
+ private struct AstryxFloatingKey: EnvironmentKey {
98
+ static let defaultValue = false
99
+ }
100
+
101
+ extension EnvironmentValues {
102
+ /// Whether `astryxFloating()` marks an enclosing container as floating.
103
+ var astryxFloating: Bool {
104
+ get { self[AstryxFloatingKey.self] }
105
+ set { self[AstryxFloatingKey.self] = newValue }
106
+ }
107
+ }
108
+
109
+ extension View {
110
+ /// Marks this container as floating over scrolling content, so the Astryx
111
+ /// Buttons inside it draw the system's Liquid Glass on iOS and iPadOS 26 and
112
+ /// later (`component:swift/Button` FR9). It only marks the container: it
113
+ /// changes no Button props, and elsewhere the Buttons keep their token look.
114
+ public func astryxFloating() -> some View {
115
+ environment(\.astryxFloating, true)
116
+ }
117
+ }
118
+
119
+ #if os(iOS)
120
+ /// Tells a Button whether a system bar hosts it. SwiftUI has no public signal
121
+ /// for this, so it looks among its UIKit ancestors for a navigation bar, a
122
+ /// toolbar, or the host SwiftUI gives each bar item (on iOS 26 the bottom bar
123
+ /// is a floating container, not a toolbar), checked whenever it moves or lays
124
+ /// out. A bar, once found, holds: the bar re-hosts a prominent item where its
125
+ /// ancestors no longer show the bar, and letting go would flip the Button
126
+ /// back and forth. The host's name is not an API, so FR7's capture gate
127
+ /// checks the navigation bar and the bottom bar on each new iOS.
128
+ struct ButtonBarProbe: UIViewRepresentable {
129
+ let report: (Bool) -> Void
130
+
131
+ func makeUIView(context: Context) -> ProbeView {
132
+ let view = ProbeView()
133
+ view.report = report
134
+ view.isUserInteractionEnabled = false
135
+ view.isAccessibilityElement = false
136
+ return view
137
+ }
138
+
139
+ func updateUIView(_ view: ProbeView, context: Context) {
140
+ view.report = report
141
+ }
142
+
143
+ final class ProbeView: UIView {
144
+ var report: ((Bool) -> Void)?
145
+ private var found = false
146
+
147
+ override func didMoveToWindow() {
148
+ super.didMoveToWindow()
149
+ check()
150
+ }
151
+
152
+ override func didMoveToSuperview() {
153
+ super.didMoveToSuperview()
154
+ check()
155
+ }
156
+
157
+ override func layoutSubviews() {
158
+ super.layoutSubviews()
159
+ check()
160
+ }
161
+
162
+ private func check() {
163
+ guard !found else { return }
164
+ var node = superview
165
+ while let view = node {
166
+ if view is UINavigationBar || view is UIToolbar
167
+ || String(describing: type(of: view)).hasPrefix("UIKitBarItemHost") {
168
+ found = true
169
+ let report = report
170
+ // Reported after this layout pass, never during it.
171
+ Task { @MainActor in report?(true) }
172
+ return
173
+ }
174
+ node = view.superview
175
+ }
176
+ }
177
+ }
178
+ }
179
+ #endif
@@ -173,7 +173,7 @@ extension Theme {
173
173
  textPrimary: Color(.sRGB, red: 0.24313725490196078, green: 0.2823529411764706, blue: 0.11372549019607843, opacity: 1),
174
174
  textPurple: Color(.sRGB, red: 0.3333333333333333, green: 0.22745098039215686, blue: 0.4392156862745098, opacity: 1),
175
175
  textRed: Color(.sRGB, red: 0.8, green: 0, blue: 0, opacity: 1),
176
- textSecondary: Color(.sRGB, red: 0.4392156862745098, green: 0.49411764705882355, blue: 0.27450980392156865, opacity: 1),
176
+ textSecondary: Color(.sRGB, red: 0.35294117647058826, green: 0.4196078431372549, blue: 0.16470588235294117, opacity: 1),
177
177
  textSuccess: Color(.sRGB, red: 0.23921568627450981, green: 0.47843137254901963, blue: 0, opacity: 1),
178
178
  textTeal: Color(.sRGB, red: 0.1411764705882353, green: 0.3333333333333333, blue: 0.27450980392156865, opacity: 1),
179
179
  textWarning: Color(.sRGB, red: 0.5137254901960784, green: 0.403921568627451, blue: 0, opacity: 1),
@@ -173,7 +173,7 @@ extension Theme {
173
173
  textPrimary: Color(.sRGB, red: 0.17647058823529413, green: 0.1411764705882353, blue: 0.10588235294117647, opacity: 1),
174
174
  textPurple: Color(.sRGB, red: 0.2627450980392157, green: 0.10196078431372549, blue: 0.5333333333333333, opacity: 1),
175
175
  textRed: Color(.sRGB, red: 0.5333333333333333, green: 0, blue: 0.13725490196078433, opacity: 1),
176
- textSecondary: Color(.sRGB, red: 0.403921568627451, green: 0.36470588235294116, blue: 0.3215686274509804, opacity: 1),
176
+ textSecondary: Color(.sRGB, red: 0.35294117647058826, green: 0.3176470588235294, blue: 0.27450980392156865, opacity: 1),
177
177
  textSuccess: Color(.sRGB, red: 0.24705882352941178, green: 0.3058823529411765, blue: 0, opacity: 1),
178
178
  textTeal: Color(.sRGB, red: 0, green: 0.3333333333333333, blue: 0.23137254901960785, opacity: 1),
179
179
  textWarning: Color(.sRGB, red: 0.34509803921568627, green: 0.26666666666666666, blue: 0, opacity: 1),
@@ -0,0 +1,149 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ import SwiftUI
4
+ import Testing
5
+ @testable import Astryx
6
+
7
+ // A Swift Button meets the system's Liquid Glass in a bar or a floating
8
+ // container on iOS and iPadOS 26, keeps its variant's meaning there, and draws
9
+ // a solid token fill under Reduce Transparency or Increase Contrast
10
+ // (component:swift/Button FR7–FR10, ORD2).
11
+
12
+ private func surface(
13
+ _ variant: ButtonVariant?, _ placement: ButtonPlacement, solid: Bool = false, glass: Bool = true
14
+ ) -> ButtonSurface {
15
+ ButtonSurface.resolve(variant: variant, placement: placement, glassAvailable: glass, prefersSolid: solid)
16
+ }
17
+
18
+ @Test func everyVariantMapsToItsGlassInABarAndFloating() {
19
+ // FR8's table: a set variant keeps its meaning; only secondary and ghost
20
+ // share the bar's glass, and in a bar primary and destructive tint it.
21
+ #expect(surface(.primary, .bar) == .glass(.barProminent(.accent)))
22
+ #expect(surface(.primary, .floating) == .glass(.prominent(.accent)))
23
+ #expect(surface(.destructive, .bar) == .glass(.barProminent(.error)))
24
+ #expect(surface(.destructive, .floating) == .glass(.prominent(.error)))
25
+ #expect(surface(.secondary, .bar) == .glass(.barItem))
26
+ #expect(surface(.secondary, .floating) == .glass(.regular))
27
+ #expect(surface(.ghost, .bar) == .glass(.barItem))
28
+ #expect(surface(.ghost, .floating) == .glass(.clear))
29
+ }
30
+
31
+ @Test func anUnsetVariantIsSecondaryEverywhere() {
32
+ for placement in [ButtonPlacement.content, .bar, .floating] {
33
+ #expect(surface(nil, placement) == surface(.secondary, placement))
34
+ #expect(surface(nil, placement, solid: true) == surface(.secondary, placement, solid: true))
35
+ }
36
+ }
37
+
38
+ @Test func contentAndPlatformsWithoutGlassKeepTheTokenLook() {
39
+ for variant in ButtonVariant.allCases {
40
+ #expect(surface(variant, .content) == .token)
41
+ #expect(surface(variant, .bar, glass: false) == .token)
42
+ #expect(surface(variant, .floating, glass: false) == .token)
43
+ #expect(surface(variant, .bar, solid: true, glass: false) == .token)
44
+ }
45
+ }
46
+
47
+ @Test func reduceTransparencyOrIncreaseContrastDrawsTheVariantsSolidFill() {
48
+ // FR10: no glass, the variant's token fill, in a bar and floating.
49
+ let roles: [ButtonVariant: ButtonColorRole] = [
50
+ .primary: .accent, .destructive: .error, .secondary: .neutral, .ghost: .surface,
51
+ ]
52
+ for (variant, role) in roles {
53
+ #expect(surface(variant, .bar, solid: true) == .solid(role, inBar: true))
54
+ #expect(surface(variant, .floating, solid: true) == .solid(role, inBar: false))
55
+ }
56
+ }
57
+
58
+ @MainActor
59
+ @Test func astryxFloatingOnlyMarksTheContainer() {
60
+ // FR9: the modifier changes no ButtonProps, only the environment.
61
+ var seen: [Bool] = []
62
+ let probe = EnvironmentReader { seen.append($0.astryxFloating) }
63
+ _ = Pixels(probe.frame(width: 4, height: 4))
64
+ _ = Pixels(probe.astryxFloating().frame(width: 4, height: 4))
65
+ #expect(seen.first == false)
66
+ #expect(seen.last == true)
67
+
68
+ let button = Astryx.Button(label: "New", variant: .primary) {}
69
+ let floating = Astryx.Button(label: "New", variant: .primary) {}
70
+ _ = floating.astryxFloating()
71
+ #expect(button.props.label == floating.props.label)
72
+ #expect(button.props.variant == floating.props.variant)
73
+ }
74
+
75
+ @MainActor
76
+ @Test func aBarButtonDrawsNoFillOrPadding() {
77
+ // FR7, FR11: the bar's glass is the only chrome, and no Astryx padding
78
+ // can cut the label short.
79
+ let accent = Theme.default.light.color.accent
80
+ let barItem = Pixels(barStyled(surface: .glass(.barItem), background: accent))
81
+ let token = Pixels(barStyled(surface: .token, background: accent))
82
+ // The bar item draws nothing above its label; the token look fills its
83
+ // padding beside the label (it sits centered in its 44-point tap frame).
84
+ #expect(barItem.at(barItem.width / 2, 1)[3] == 0)
85
+ #expect(close(token.at(8, token.height / 2), rgba(accent)))
86
+ #expect(barItem.width < token.width)
87
+ }
88
+
89
+ @MainActor
90
+ @Test func theProminentBarFallbackDrawsALabelInItsVariantsColor() {
91
+ // Where SwiftUI's prominent glass style is unavailable, a primary bar
92
+ // Button draws no fill and keeps primary's accent in its label; disabled,
93
+ // it dims.
94
+ let accent = rgba(Theme.default.light.color.accent)
95
+ let drawn = Pixels(barStyled(surface: .glass(.barProminent(.accent)), isDimmed: true))
96
+ #expect(drawn.at(drawn.width / 2, 1)[3] == 0)
97
+ // Pixels are premultiplied: a glyph pixel's color over its alpha is the
98
+ // label's color, and half opacity caps its alpha.
99
+ #expect(drawn.contains { p in
100
+ p[3] > 40 && (1...2).allSatisfy { abs(p[$0] * 255 / p[3] - accent[$0]) <= 24 }
101
+ })
102
+ #expect(!drawn.contains { $0[3] > 140 })
103
+ }
104
+
105
+ @MainActor
106
+ @Test func aSolidFallbackDrawsTheFillWithAnEmphasizedEdge() {
107
+ let tokens = Theme.default.light
108
+ let solid = Pixels(barStyled(surface: .solid(.surface, inBar: false)))
109
+ #expect(close(solid.at(0, solid.height / 2), rgba(tokens.color.borderEmphasized)))
110
+ #expect(close(solid.at(8, solid.height / 2), rgba(tokens.color.backgroundSurface)))
111
+ }
112
+
113
+ @MainActor
114
+ @Test func aSolidNeutralFillIsOpaqueOverContent() {
115
+ // FR10's solid fill hides what is behind it: the translucent neutral token
116
+ // draws on the surface color, as it reads on a page.
117
+ let solid = Pixels(barStyled(surface: .solid(.neutral, inBar: false)).background(Color.black))
118
+ let pixel = solid.at(8, solid.height / 2)
119
+ // The light surface, tinted by neutral, not the black content behind it.
120
+ #expect(pixel[3] == 255)
121
+ #expect(pixel[0...2].allSatisfy { $0 > 200 })
122
+ }
123
+
124
+ /// A Button's style drawn alone at a given surface.
125
+ @MainActor
126
+ private func barStyled(
127
+ surface: ButtonSurface, background: Color? = nil, isDimmed: Bool = false
128
+ ) -> some View {
129
+ let astryx = EnvironmentValues().astryx
130
+ return SwiftUI.Button("Share") {}
131
+ .buttonStyle(
132
+ AstryxButtonStyle(
133
+ astryx: astryx, height: astryx.tokens.size.elementMd, fillsWidth: false,
134
+ foreground: astryx.tokens.color.textPrimary,
135
+ background: background ?? astryx.tokens.color.neutral, shadow: [], isDimmed: isDimmed, surface: surface
136
+ )
137
+ )
138
+ .fixedSize()
139
+ }
140
+
141
+ /// Reports the environment it is drawn in.
142
+ private struct EnvironmentReader: View {
143
+ let read: (EnvironmentValues) -> Void
144
+ @Environment(\.self) private var environment
145
+ var body: some View {
146
+ read(environment)
147
+ return Color.clear
148
+ }
149
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astryxdesign/native",
3
- "version": "0.7.12-canary.07e325e",
3
+ "version": "0.7.12-canary.0840fcc",
4
4
  "description": "Experimental native platforms for Astryx (iOS, Android, macOS, Windows) — published to npm only under the @canary dist-tag; never released as a stable (latest) version.",
5
5
  "author": "Meta Open Source",
6
6
  "license": "MIT",
@@ -70,10 +70,10 @@
70
70
  }
71
71
  },
72
72
  "peerDependencies": {
73
- "@astryxdesign/core": "0.7.12-canary.07e325e"
73
+ "@astryxdesign/core": "0.7.12-canary.0840fcc"
74
74
  },
75
75
  "devDependencies": {
76
- "@astryxdesign/core": "0.7.12-canary.07e325e"
76
+ "@astryxdesign/core": "0.7.12-canary.0840fcc"
77
77
  },
78
78
  "scripts": {
79
79
  "build": "node ../../scripts/clean-dist.mjs && tsc --project tsconfig.build.json && node scripts/generate.mjs --types",