Skip to content

Commit fbba3f6

Browse files
committed
Address mobile navigation review feedback
Signed-off-by: kenny lopez <[email protected]>
1 parent eac4268 commit fbba3f6

5 files changed

Lines changed: 194 additions & 24 deletions

File tree

‎mobile/ios/Runner/JumpToLatestGlassButton.swift‎

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,17 +255,44 @@ final class NavigationGlassButtonPlatformView: NSObject, FlutterPlatformView {
255255
containerView
256256
}
257257

258-
/// Whether the pre-iOS-26 fallback should use a dark surface so a light
259-
/// foreground remains visible over media.
258+
/// Whether the pre-iOS-26 fallback should use a dark surface so the
259+
/// foreground maintains non-text UI contrast in light appearance.
260260
static func usesDarkFallbackSurface(
261261
foregroundColor: UIColor?,
262262
interfaceStyle: UIUserInterfaceStyle
263263
) -> Bool {
264264
guard interfaceStyle != .dark, let foregroundColor else { return false }
265-
var white: CGFloat = 0
265+
let traits = UITraitCollection(userInterfaceStyle: interfaceStyle)
266+
let backgroundColor = UIColor.secondarySystemBackground.resolvedColor(with: traits)
267+
guard
268+
let foregroundLuminance = relativeLuminance(
269+
of: foregroundColor.resolvedColor(with: traits)
270+
),
271+
let backgroundLuminance = relativeLuminance(of: backgroundColor)
272+
else { return false }
273+
let lighter = max(foregroundLuminance, backgroundLuminance)
274+
let darker = min(foregroundLuminance, backgroundLuminance)
275+
return (lighter + 0.05) / (darker + 0.05) < 3
276+
}
277+
278+
private static func relativeLuminance(of color: UIColor) -> CGFloat? {
279+
var red: CGFloat = 0
280+
var green: CGFloat = 0
281+
var blue: CGFloat = 0
266282
var alpha: CGFloat = 0
267-
guard foregroundColor.getWhite(&white, alpha: &alpha) else { return false }
268-
return alpha > 0.5 && white >= 0.9
283+
guard color.getRed(&red, green: &green, blue: &blue, alpha: &alpha) else {
284+
return nil
285+
}
286+
287+
func linearize(_ component: CGFloat) -> CGFloat {
288+
component <= 0.04045
289+
? component / 12.92
290+
: pow((component + 0.055) / 1.055, 2.4)
291+
}
292+
293+
return 0.2126 * linearize(red) +
294+
0.7152 * linearize(green) +
295+
0.0722 * linearize(blue)
269296
}
270297

271298
private func applyAppearance(from value: Any?) {

‎mobile/ios/RunnerTests/RunnerTests.swift‎

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@ import XCTest
55

66
@testable import Buzz
77

8+
private extension UIColor {
9+
convenience init(hex: UInt32) {
10+
self.init(
11+
red: CGFloat((hex >> 16) & 0xFF) / 255,
12+
green: CGFloat((hex >> 8) & 0xFF) / 255,
13+
blue: CGFloat(hex & 0xFF) / 255,
14+
alpha: 1
15+
)
16+
}
17+
}
18+
819
class RunnerTests: XCTestCase {
920

1021
func testNavigationGlassButtonExpandsToConfiguredHitTarget() {
@@ -25,25 +36,60 @@ class RunnerTests: XCTestCase {
2536
XCTAssertFalse(button.point(inside: CGPoint(x: -1, y: 20), with: nil))
2637
}
2738

28-
func testNavigationGlassFallbackUsesDarkSurfaceForWhiteGlyphInLightMode() {
39+
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),
51+
]
52+
53+
for accent in accents {
54+
XCTAssertEqual(
55+
NavigationGlassButtonPlatformView.usesDarkFallbackSurface(
56+
foregroundColor: accent.color,
57+
interfaceStyle: .light
58+
),
59+
accent.usesDarkSurface,
60+
accent.name
61+
)
62+
}
2963
XCTAssertTrue(
3064
NavigationGlassButtonPlatformView.usesDarkFallbackSurface(
3165
foregroundColor: .white,
3266
interfaceStyle: .light
3367
)
3468
)
35-
XCTAssertFalse(
36-
NavigationGlassButtonPlatformView.usesDarkFallbackSurface(
37-
foregroundColor: .white,
38-
interfaceStyle: .dark
39-
)
40-
)
41-
XCTAssertFalse(
42-
NavigationGlassButtonPlatformView.usesDarkFallbackSurface(
43-
foregroundColor: .systemBlue,
44-
interfaceStyle: .light
69+
}
70+
71+
func testNavigationGlassFallbackKeepsSystemSurfaceInDarkMode() {
72+
let darkAccents = [
73+
UIColor(hex: 0xE1E4E8),
74+
UIColor(hex: 0x60A5FA),
75+
UIColor(hex: 0x22D3EE),
76+
UIColor(hex: 0x4ADE80),
77+
UIColor(hex: 0xFB923C),
78+
UIColor(hex: 0xF87171),
79+
UIColor(hex: 0xF472B6),
80+
UIColor(hex: 0xC0A2F1),
81+
UIColor(hex: 0xC084FC),
82+
UIColor(hex: 0x818CF8),
83+
]
84+
85+
for accent in darkAccents {
86+
XCTAssertFalse(
87+
NavigationGlassButtonPlatformView.usesDarkFallbackSurface(
88+
foregroundColor: accent,
89+
interfaceStyle: .dark
90+
)
4591
)
46-
)
92+
}
4793
}
4894

4995
func testRelativeTrackInsertionTimesPreserveAudioDelay() {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ class ChannelDetailPage extends HookConsumerWidget {
340340
titleStyle: channelTitleTextStyle,
341341
title: Padding(
342342
padding: EdgeInsets.only(
343-
left: Navigator.canPop(context)
343+
left: usesNativeIosGlassBackButton
344344
? iosGlassChannelHeaderTitleSpacing
345345
: 0,
346346
),

‎mobile/lib/features/channels/thread_detail_page.dart‎

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,19 @@ const _landingHighlightTransitionDuration = Duration(milliseconds: 300);
5959
const _landingHighlightOpacity = 0.12;
6060
const _threadTailScrollTolerance = 0.5;
6161

62+
/// Returns whether a bounded tail correction reached the effective end.
63+
///
64+
/// Item positions can lag the active scroll position by a frame, so an exact
65+
/// end-of-scroll measurement is sufficient even while the tail item still
66+
/// reports outside the visible boundary.
67+
@visibleForTesting
68+
bool threadTailCorrectionReachedEnd({
69+
required bool tailIsVisible,
70+
required double? extentAfter,
71+
}) =>
72+
tailIsVisible ||
73+
(extentAfter != null && extentAfter <= _threadTailScrollTolerance);
74+
6275
// Keep the direct-position correction finite in case the viewport cannot
6376
// expose its tail (for example, continuously changing media dimensions).
6477
const _latestTailCorrectionLimit = 8;
@@ -402,11 +415,12 @@ class ThreadDetailPage extends HookConsumerWidget {
402415
// trust an exact end-of-scroll position too: there is nowhere further
403416
// for Latest to navigate, so leaving the control visible is misleading.
404417
final position = activeThreadScrollPosition.value;
405-
final reachedScrollExtent =
406-
position != null &&
407-
position.hasContentDimensions &&
408-
position.extentAfter <= _threadTailScrollTolerance;
409-
isAtThreadTail.value = reachedTail || reachedScrollExtent;
418+
isAtThreadTail.value = threadTailCorrectionReachedEnd(
419+
tailIsVisible: reachedTail,
420+
extentAfter: position != null && position.hasContentDimensions
421+
? position.extentAfter
422+
: null,
423+
);
410424
}
411425

412426
void correctThreadTailInstantly() {

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

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import 'dart:convert';
33

44
import 'package:flutter/foundation.dart';
55
import 'package:flutter/material.dart';
6-
import 'package:flutter/rendering.dart' show ScrollDirection, SemanticsAction;
6+
import 'package:flutter/rendering.dart'
7+
show RenderParagraph, ScrollDirection, SemanticsAction;
78
import 'package:flutter/services.dart';
89
import 'package:flutter_test/flutter_test.dart';
910
import 'package:hooks_riverpod/hooks_riverpod.dart';
@@ -5368,6 +5369,74 @@ void main() {
53685369
},
53695370
);
53705371

5372+
for (final platform in [TargetPlatform.android, TargetPlatform.iOS]) {
5373+
testWidgets(
5374+
'keeps a narrow long channel title aligned on ${platform.name}',
5375+
(tester) async {
5376+
final previousPlatform = debugDefaultTargetPlatformOverride;
5377+
debugDefaultTargetPlatformOverride = platform;
5378+
addTearDown(
5379+
() => debugDefaultTargetPlatformOverride = previousPlatform,
5380+
);
5381+
tester.view.physicalSize = const Size(320, 700);
5382+
tester.view.devicePixelRatio = 1;
5383+
addTearDown(tester.view.reset);
5384+
final channel = _testChannel.copyWith(
5385+
name: 'a-very-long-channel-name-that-must-truncate',
5386+
);
5387+
5388+
await tester.pumpWidget(
5389+
_buildTestable(
5390+
messages: const [],
5391+
channel: channel,
5392+
home: Builder(
5393+
builder: (context) => Scaffold(
5394+
body: TextButton(
5395+
onPressed: () => Navigator.of(context).push(
5396+
MaterialPageRoute<void>(
5397+
builder: (_) => ChannelDetailPage(channel: channel),
5398+
),
5399+
),
5400+
child: const Text('Open channel'),
5401+
),
5402+
),
5403+
),
5404+
),
5405+
);
5406+
await tester.pumpAndSettle();
5407+
5408+
await tester.tap(find.text('Open channel'));
5409+
await tester.pumpAndSettle();
5410+
5411+
final backRect = platform == TargetPlatform.iOS
5412+
? tester.getRect(
5413+
find.byKey(const ValueKey('channel-ios-glass-back')),
5414+
)
5415+
: tester.getRect(find.byTooltip('Back'));
5416+
final avatarRect = tester.getRect(
5417+
find.byKey(const ValueKey('channel-header-avatar')),
5418+
);
5419+
final titleSpacing = avatarRect.left - backRect.right;
5420+
final title = tester.renderObject<RenderParagraph>(
5421+
find.byKey(const ValueKey('channel-header-name')),
5422+
);
5423+
final titleDidExceedMaxLines = title.didExceedMaxLines;
5424+
debugDefaultTargetPlatformOverride = previousPlatform;
5425+
5426+
expect(
5427+
titleSpacing,
5428+
moreOrLessEquals(
5429+
platform == TargetPlatform.iOS
5430+
? iosGlassChannelHeaderTitleSpacing
5431+
: 0,
5432+
),
5433+
);
5434+
expect(titleDidExceedMaxLines, isTrue);
5435+
expect(tester.takeException(), isNull);
5436+
},
5437+
);
5438+
}
5439+
53715440
testWidgets('shows a tappable channel name and collective member count', (
53725441
tester,
53735442
) async {
@@ -8926,6 +8995,20 @@ void main() {
89268995
expect(find.byKey(const ValueKey('thread-jump-to-latest')), findsNothing);
89278996
});
89288997

8998+
test(
8999+
'thread tail accepts exact scroll extent while item positions lag',
9000+
() {
9001+
expect(
9002+
threadTailCorrectionReachedEnd(tailIsVisible: false, extentAfter: 0),
9003+
isTrue,
9004+
);
9005+
expect(
9006+
threadTailCorrectionReachedEnd(tailIsVisible: false, extentAfter: 1),
9007+
isFalse,
9008+
);
9009+
},
9010+
);
9011+
89299012
testWidgets('thread Latest settles across expanding lazy scroll extents', (
89309013
tester,
89319014
) async {

0 commit comments

Comments
 (0)