Skip to content

Commit 9a6fd3b

Browse files
committed
fix(mobile): keep channel subtitle neutral
Signed-off-by: kenny lopez <[email protected]>
1 parent fbba3f6 commit 9a6fd3b

4 files changed

Lines changed: 54 additions & 39 deletions

File tree

‎mobile/ios/Runner/JumpToLatestGlassButton.swift‎

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -255,24 +255,33 @@ final class NavigationGlassButtonPlatformView: NSObject, FlutterPlatformView {
255255
containerView
256256
}
257257

258-
/// Whether the pre-iOS-26 fallback should use a dark surface so the
259-
/// foreground maintains non-text UI contrast in light appearance.
260-
static func usesDarkFallbackSurface(
258+
/// Returns the pre-iOS-26 surface that maximizes contrast with the requested
259+
/// foreground while preserving the system surface when it already passes.
260+
static func fallbackBackgroundColor(
261261
foregroundColor: UIColor?,
262262
interfaceStyle: UIUserInterfaceStyle
263-
) -> Bool {
264-
guard interfaceStyle != .dark, let foregroundColor else { return false }
263+
) -> UIColor {
265264
let traits = UITraitCollection(userInterfaceStyle: interfaceStyle)
266265
let backgroundColor = UIColor.secondarySystemBackground.resolvedColor(with: traits)
266+
guard interfaceStyle != .dark, let foregroundColor else { return backgroundColor }
267+
let resolvedForeground = foregroundColor.resolvedColor(with: traits)
268+
if contrastRatio(foregroundColor: resolvedForeground, backgroundColor: backgroundColor) >= 3 {
269+
return backgroundColor
270+
}
271+
return .black
272+
}
273+
274+
static func contrastRatio(
275+
foregroundColor: UIColor,
276+
backgroundColor: UIColor
277+
) -> CGFloat {
267278
guard
268-
let foregroundLuminance = relativeLuminance(
269-
of: foregroundColor.resolvedColor(with: traits)
270-
),
279+
let foregroundLuminance = relativeLuminance(of: foregroundColor),
271280
let backgroundLuminance = relativeLuminance(of: backgroundColor)
272-
else { return false }
281+
else { return 1 }
273282
let lighter = max(foregroundLuminance, backgroundLuminance)
274283
let darker = min(foregroundLuminance, backgroundLuminance)
275-
return (lighter + 0.05) / (darker + 0.05) < 3
284+
return (lighter + 0.05) / (darker + 0.05)
276285
}
277286

278287
private static func relativeLuminance(of color: UIColor) -> CGFloat? {
@@ -310,10 +319,10 @@ final class NavigationGlassButtonPlatformView: NSObject, FlutterPlatformView {
310319
button.configuration?.baseForegroundColor = foregroundColor
311320
}
312321
if #unavailable(iOS 26.0) {
313-
button.configuration?.baseBackgroundColor = Self.usesDarkFallbackSurface(
322+
button.configuration?.baseBackgroundColor = Self.fallbackBackgroundColor(
314323
foregroundColor: foregroundColor,
315324
interfaceStyle: interfaceStyle
316-
) ? UIColor.black.withAlphaComponent(0.62) : UIColor.secondarySystemBackground
325+
)
317326
}
318327
button.setNeedsUpdateConfiguration()
319328
}

‎mobile/ios/RunnerTests/RunnerTests.swift‎

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -37,35 +37,34 @@ class RunnerTests: XCTestCase {
3737
}
3838

3939
func testNavigationGlassFallbackContrastsSupportedAccentsInLightMode() {
40-
let accents: [(name: String, color: UIColor, usesDarkSurface: Bool)] = [
41-
("Neutral", UIColor(hex: 0x000000), false),
42-
("Blue", UIColor(hex: 0x3B82F6), false),
43-
("Cyan", UIColor(hex: 0x06B6D4), true),
44-
("Green", UIColor(hex: 0x22C55E), true),
45-
("Orange", UIColor(hex: 0xF97316), true),
46-
("Red", UIColor(hex: 0xEF4444), false),
47-
("Pink", UIColor(hex: 0xEC4899), false),
48-
("Lilac", UIColor(hex: 0xC0A2F1), true),
49-
("Purple", UIColor(hex: 0xA855F7), false),
50-
("Indigo", UIColor(hex: 0x6366F1), false),
40+
let accents: [(name: String, color: UIColor)] = [
41+
("Neutral", UIColor(hex: 0x000000)),
42+
("Blue", UIColor(hex: 0x3B82F6)),
43+
("Cyan", UIColor(hex: 0x06B6D4)),
44+
("Green", UIColor(hex: 0x22C55E)),
45+
("Orange", UIColor(hex: 0xF97316)),
46+
("Red", UIColor(hex: 0xEF4444)),
47+
("Pink", UIColor(hex: 0xEC4899)),
48+
("Lilac", UIColor(hex: 0xC0A2F1)),
49+
("Purple", UIColor(hex: 0xA855F7)),
50+
("Indigo", UIColor(hex: 0x6366F1)),
51+
("White", .white),
5152
]
5253

5354
for accent in accents {
54-
XCTAssertEqual(
55-
NavigationGlassButtonPlatformView.usesDarkFallbackSurface(
55+
let background = NavigationGlassButtonPlatformView.fallbackBackgroundColor(
56+
foregroundColor: accent.color,
57+
interfaceStyle: .light
58+
)
59+
XCTAssertGreaterThanOrEqual(
60+
NavigationGlassButtonPlatformView.contrastRatio(
5661
foregroundColor: accent.color,
57-
interfaceStyle: .light
62+
backgroundColor: background
5863
),
59-
accent.usesDarkSurface,
64+
3,
6065
accent.name
6166
)
6267
}
63-
XCTAssertTrue(
64-
NavigationGlassButtonPlatformView.usesDarkFallbackSurface(
65-
foregroundColor: .white,
66-
interfaceStyle: .light
67-
)
68-
)
6968
}
7069

7170
func testNavigationGlassFallbackKeepsSystemSurfaceInDarkMode() {
@@ -83,11 +82,16 @@ class RunnerTests: XCTestCase {
8382
]
8483

8584
for accent in darkAccents {
86-
XCTAssertFalse(
87-
NavigationGlassButtonPlatformView.usesDarkFallbackSurface(
85+
let background = NavigationGlassButtonPlatformView.fallbackBackgroundColor(
86+
foregroundColor: accent,
87+
interfaceStyle: .dark
88+
)
89+
XCTAssertGreaterThanOrEqual(
90+
NavigationGlassButtonPlatformView.contrastRatio(
8891
foregroundColor: accent,
89-
interfaceStyle: .dark
90-
)
92+
backgroundColor: background
93+
),
94+
3
9195
)
9296
}
9397
}

‎mobile/lib/features/channels/channel_detail_page/app_bar.dart‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@ class _ChannelAppBarTitle extends ConsumerWidget {
121121
maxLines: 1,
122122
overflow: TextOverflow.ellipsis,
123123
style: context.textTheme.bodySmall?.copyWith(
124-
color: context.colors.primary.withValues(alpha: 0.65),
124+
color: context.colors.onSurface.withValues(
125+
alpha: 0.65,
126+
),
125127
),
126128
),
127129
],

‎mobile/test/features/channels/channel_detail_page_test.dart‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5540,7 +5540,7 @@ void main() {
55405540
)
55415541
.style
55425542
?.color,
5543-
AppTheme.light().colorScheme.primary.withValues(alpha: 0.65),
5543+
AppTheme.light().colorScheme.onSurface.withValues(alpha: 0.65),
55445544
);
55455545
expect(find.byTooltip('View members'), findsNothing);
55465546
expect(find.byTooltip('Channel actions'), findsNothing);

0 commit comments

Comments
 (0)