Skip to content

Commit fceb7ac

Browse files
committed
fix(mobile): composite nav controls under backdrops
Signed-off-by: kenny lopez <[email protected]>
1 parent 9a6fd3b commit fceb7ac

5 files changed

Lines changed: 129 additions & 31 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import 'jump_to_latest_button.dart';
5050
import 'jump_to_latest_switcher.dart';
5151
import 'members_sheet.dart';
5252
import 'message_actions.dart';
53+
import 'message_action_backdrop_state.dart';
5354
import 'message_long_press_region.dart';
5455
import 'message_content.dart';
5556
import '../../shared/read_state/deferred_read_state_update.dart';
@@ -333,6 +334,7 @@ class ChannelDetailPage extends HookConsumerWidget {
333334
onPressed: () => Navigator.of(context).maybePop(),
334335
width: iosGlassChannelHeaderLeadingWidth,
335336
buttonCenterX: iosGlassChannelHeaderButtonCenterX,
337+
nativeViewSuppressed: messageActionBackdropActive,
336338
)
337339
: null,
338340
iconColor: context.colors.primary,

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
part of 'thread_detail_page.dart';
22

3+
/// Returns whether a bounded tail correction reached the effective end.
4+
///
5+
/// Item positions can lag the active scroll position by a frame, so an exact
6+
/// end-of-scroll measurement is sufficient even while the tail item still
7+
/// reports outside the visible boundary.
8+
@visibleForTesting
9+
bool threadTailCorrectionReachedEnd({
10+
required bool tailIsVisible,
11+
required double? extentAfter,
12+
}) =>
13+
tailIsVisible ||
14+
(extentAfter != null && extentAfter <= _threadTailScrollTolerance);
15+
316
int _threadTailIndex(int replyCount) => replyCount;
417

518
void _resumeThreadTailFollow({

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

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import 'jump_to_latest_button.dart';
3535
import 'jump_to_latest_switcher.dart';
3636
import '../profile/user_profile_sheet.dart';
3737
import 'message_actions.dart';
38+
import 'message_action_backdrop_state.dart';
3839
import 'message_long_press_region.dart';
3940
import 'message_content.dart';
4041
import 'reaction_row.dart';
@@ -59,19 +60,6 @@ const _landingHighlightTransitionDuration = Duration(milliseconds: 300);
5960
const _landingHighlightOpacity = 0.12;
6061
const _threadTailScrollTolerance = 0.5;
6162

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-
7563
// Keep the direct-position correction finite in case the viewport cannot
7664
// expose its tail (for example, continuously changing media dimensions).
7765
const _latestTailCorrectionLimit = 8;
@@ -847,6 +835,7 @@ class ThreadDetailPage extends HookConsumerWidget {
847835
onPressed: () => Navigator.of(context).maybePop(),
848836
width: iosGlassChannelHeaderLeadingWidth,
849837
buttonCenterX: iosGlassChannelHeaderButtonCenterX,
838+
nativeViewSuppressed: messageActionBackdropActive,
850839
)
851840
: null,
852841
iconColor: context.colors.primary,

‎mobile/lib/shared/widgets/ios_glass_navigation_button.dart‎

Lines changed: 67 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class IosGlassNavigationButton extends HookWidget {
3434
this.height = 48,
3535
this.buttonCenterX,
3636
this.foregroundColor,
37+
this.nativeViewSuppressed,
3738
});
3839

3940
static const viewType = 'buzz/navigation_glass';
@@ -45,6 +46,7 @@ class IosGlassNavigationButton extends HookWidget {
4546
final double height;
4647
final double? buttonCenterX;
4748
final Color? foregroundColor;
49+
final ValueListenable<bool>? nativeViewSuppressed;
4850

4951
@override
5052
Widget build(BuildContext context) {
@@ -81,29 +83,76 @@ class IosGlassNavigationButton extends HookWidget {
8183
return null;
8284
}, [nativeChannel.value, brightness, foregroundValue, enabled]);
8385

86+
Widget buildControl({required bool suppressNativeView}) {
87+
if (suppressNativeView) {
88+
final resolvedButtonCenterX = buttonCenterX ?? width / 2;
89+
return Stack(
90+
key: const ValueKey('ios-glass-navigation-flutter-fallback'),
91+
children: [
92+
Positioned(
93+
left: resolvedButtonCenterX - 20,
94+
top: (height - 40) / 2,
95+
width: 40,
96+
height: 40,
97+
child: DecoratedBox(
98+
decoration: BoxDecoration(
99+
color: context.colors.surface.withValues(alpha: 0.72),
100+
shape: BoxShape.circle,
101+
border: Border.all(
102+
color: context.colors.inverseSurface.withValues(
103+
alpha: 0.07,
104+
),
105+
),
106+
),
107+
child: Icon(
108+
icon == IosGlassNavigationIcon.back
109+
? Icons.arrow_back_ios_new_rounded
110+
: Icons.close_rounded,
111+
size: 20,
112+
color: effectiveForeground,
113+
),
114+
),
115+
),
116+
],
117+
);
118+
}
119+
return UiKitView(
120+
viewType: viewType,
121+
hitTestBehavior: PlatformViewHitTestBehavior.opaque,
122+
creationParams: <String, Object>{
123+
'icon': icon.name,
124+
'accessibilityLabel': semanticLabel,
125+
'brightness': brightness,
126+
'foregroundColor': foregroundValue,
127+
'enabled': enabled,
128+
'buttonCenterX': buttonCenterX ?? width / 2,
129+
'hitTargetWidth': width,
130+
'hitTargetHeight': height,
131+
},
132+
creationParamsCodec: const StandardMessageCodec(),
133+
onPlatformViewCreated: (viewId) {
134+
nativeChannel.value = MethodChannel('$viewType/$viewId');
135+
},
136+
);
137+
}
138+
84139
return Tooltip(
85140
message: semanticLabel,
86141
child: SizedBox(
87142
width: width,
88143
height: height,
89-
child: UiKitView(
90-
viewType: viewType,
91-
hitTestBehavior: PlatformViewHitTestBehavior.opaque,
92-
creationParams: <String, Object>{
93-
'icon': icon.name,
94-
'accessibilityLabel': semanticLabel,
95-
'brightness': brightness,
96-
'foregroundColor': foregroundValue,
97-
'enabled': enabled,
98-
'buttonCenterX': buttonCenterX ?? width / 2,
99-
'hitTargetWidth': width,
100-
'hitTargetHeight': height,
101-
},
102-
creationParamsCodec: const StandardMessageCodec(),
103-
onPlatformViewCreated: (viewId) {
104-
nativeChannel.value = MethodChannel('$viewType/$viewId');
105-
},
106-
),
144+
child: nativeViewSuppressed == null
145+
? buildControl(suppressNativeView: false)
146+
: ValueListenableBuilder<bool>(
147+
valueListenable: nativeViewSuppressed!,
148+
builder: (context, suppressNativeView, _) => IgnorePointer(
149+
ignoring: suppressNativeView,
150+
child: ExcludeSemantics(
151+
excluding: suppressNativeView,
152+
child: buildControl(suppressNativeView: suppressNativeView),
153+
),
154+
),
155+
),
107156
),
108157
);
109158
}

‎mobile/test/shared/widgets/frosted_app_bar_test.dart‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:buzz/shared/theme/theme.dart';
22
import 'package:buzz/shared/widgets/frosted_app_bar.dart';
3+
import 'package:buzz/shared/widgets/ios_glass_navigation_button.dart';
34
import 'package:flutter/material.dart';
45
import 'package:flutter/foundation.dart';
56
import 'package:flutter_test/flutter_test.dart';
@@ -122,4 +123,48 @@ void main() {
122123
expect(find.byTooltip('Back'), findsOneWidget);
123124
debugDefaultTargetPlatformOverride = null;
124125
});
126+
127+
testWidgets('replaces native glass while a Flutter backdrop is active', (
128+
tester,
129+
) async {
130+
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
131+
addTearDown(() => debugDefaultTargetPlatformOverride = null);
132+
final suppressNativeView = ValueNotifier(false);
133+
addTearDown(suppressNativeView.dispose);
134+
135+
await tester.pumpWidget(
136+
MaterialApp(
137+
theme: AppTheme.light(),
138+
home: Scaffold(
139+
body: IosGlassNavigationButton(
140+
icon: IosGlassNavigationIcon.back,
141+
semanticLabel: 'Back',
142+
onPressed: () {},
143+
nativeViewSuppressed: suppressNativeView,
144+
),
145+
),
146+
),
147+
);
148+
149+
expect(find.byType(UiKitView), findsOneWidget);
150+
expect(
151+
find.byKey(const ValueKey('ios-glass-navigation-flutter-fallback')),
152+
findsNothing,
153+
);
154+
155+
suppressNativeView.value = true;
156+
await tester.pump();
157+
158+
expect(find.byType(UiKitView), findsNothing);
159+
expect(
160+
find.byKey(const ValueKey('ios-glass-navigation-flutter-fallback')),
161+
findsOneWidget,
162+
);
163+
164+
suppressNativeView.value = false;
165+
await tester.pump();
166+
167+
expect(find.byType(UiKitView), findsOneWidget);
168+
debugDefaultTargetPlatformOverride = null;
169+
});
125170
}

0 commit comments

Comments
 (0)