Skip to content

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

TypeScript

feat(native): Swift borders use the emphasized color under Increase Contrast (#8291)

Cindy Zhangc4798656a5d2
diff --git a/packages/native/apple/Sources/Astryx/Theme/Theme.swift b/packages/native/apple/Sources/Astryx/Theme/Theme.swift
index 4afa1a6f22..f68578720b 100644
--- a/packages/native/apple/Sources/Astryx/Theme/Theme.swift
+++ b/packages/native/apple/Sources/Astryx/Theme/Theme.swift
@@ -242,7 +242,7 @@ extension EnvironmentValues {
public var astryx: AstryxStyle {
let theme = astryxTheme
return AstryxStyle(
- tokens: colorScheme == .dark ? theme.dark : theme.light,
+ tokens: astryxTokens(theme, scheme: colorScheme, contrast: colorSchemeContrast),
textScale: astryxTextScale(for: dynamicTypeSize),
icons: theme.icons,
isBoldText: legibilityWeight == .bold
@@ -250,6 +250,17 @@ extension EnvironmentValues {
}
}
+/// A theme's tokens for a color scheme and contrast. With Increase Contrast
+/// on, borders and separators use the emphasized border color, since core has
+/// no contrast mode (theme generator spec, D4).
+func astryxTokens(_ theme: Theme, scheme: ColorScheme, contrast: ColorSchemeContrast) -> Tokens {
+ var tokens = scheme == .dark ? theme.dark : theme.light
+ if contrast == .increased {
+ tokens.color.border = tokens.color.borderEmphasized
+ }
+ return tokens
+}
+
extension View {
/// Paints this subtree with a theme. Components follow the color scheme and
/// the person's text size either way.
diff --git a/packages/native/apple/Tests/AstryxTests/EnvironmentTests.swift b/packages/native/apple/Tests/AstryxTests/EnvironmentTests.swift
index 7880a39977..116e46c6fb 100644
--- a/packages/native/apple/Tests/AstryxTests/EnvironmentTests.swift
+++ b/packages/native/apple/Tests/AstryxTests/EnvironmentTests.swift
@@ -64,3 +64,24 @@ import Testing
environment.legibilityWeight = .bold
#expect(environment.astryx.isBoldText)
}
+
+// Theme generator spec D4 and theme environment spec E1: with Increase
+// Contrast on, borders use the emphasized border color.
+
+@Test func increaseContrastEmphasizesBorders() {
+ for scheme in [ColorScheme.light, .dark] {
+ let mode = scheme == .dark ? Theme.default.dark : Theme.default.light
+ let standard = astryxTokens(.default, scheme: scheme, contrast: .standard)
+ let increased = astryxTokens(.default, scheme: scheme, contrast: .increased)
+ #expect(standard.color.border == mode.color.border)
+ #expect(increased.color.border == mode.color.borderEmphasized)
+ #expect(increased.color.textPrimary == mode.color.textPrimary)
+ }
+}
+
+@Test func theStyleCardsDrawWithFollowsContrast() {
+ var environment = EnvironmentValues()
+ #expect(environment.astryx.color("color-border") == Theme.default.light.color.border)
+ environment.astryxTheme = .neutral
+ #expect(environment.astryx.color("color-border") == Theme.neutral.light.color.border)
+}