fix(mobile): keep glass controls mounted and the wide thread push parallax (#9726)

Fixes three regressions that #9717 (Duo chat switching) introduced.

**Glass controls blank when anything covers their route.** #9717 gated
`IosGlassNavigationButton` and `IosGlassNavigationAction` on
`useNativeRouteControlsVisible`, so every glass control (Home's filter
chips, glass Back, Close, Done) unmounted under any dialog, alert or
modal sheet and during every push, pop and back swipe, then came back as
a new platform view near the end of the transition. This drops the gate
from those two widgets, which restores their behaviour from before
#9717. The problem #9717 targets is unaffected: under Search and
Activity sheets the hook already returns true and the opaque backing
hides the controls. Home's gate, the Channels route sync and
`IosMessageCreateButton` keep the hook.

**The visibility hook rebuilt its host on every animation frame.** It
subscribed to the route's animation values but only reads whether the
covering animation is at zero and whether the route is reversing. It now
uses `useListenableSelector` on those two booleans, so a host rebuilds
only when visibility can change.

**A wide thread push lost the outgoing chat's slide.** For an immediate
wide selection, `_ConversationDetailRoute.buildTransitions` returned its
child directly, which also discarded the secondary animation that moves
the chat left when a thread is pushed over it. It now builds the
platform transition with a completed primary animation, so selection
stays immediate and the covered chat keeps its parallax.

### Regressions

- Glass controls go back to staying mounted under covering routes, as
they did before #9717. Platform-view bleed under non-sheet routes is
therefore the pre-#9717 behaviour, not new.
- No change to compact navigation or to the Search and Activity sheet
composition.

### Validation

Added tests:
-
[native_route_controls_test.dart](fb0d16ef56/mobile/test/shared/widgets/native_route_controls_test.dart):
glass controls stay mounted, with the same channels, under a dialog and
keep receiving appearance updates, while only the create control
unmounts and returns; glass controls stay mounted with no platform-view
churn across a modal bottom sheet; the `bottomUp=false` composition case
keeps the glass views; the hook rebuilds its host a small constant
number of times across a full push and pop.
-
[adaptive_conversation_pane_test.dart](fb0d16ef56/mobile/test/shared/widgets/adaptive_conversation_pane_test.dart):
in the wide layout, the covered chat has moved left 150 ms into a thread
push on iOS.

Signed-off-by: Tom Brow <tomb@block.xyz>
Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@localhost>
This commit is contained in:
Tom Brow
2026-11-19 10:09:17 -08:00
committed by GitHub
parent bf1cd5500d
commit 7361326717
6 changed files with 307 additions and 161 deletions

View File

@@ -601,9 +601,12 @@ class _ConversationDetailRoute extends MaterialPageRoute<void> {
Animation<double> animation,
Animation<double> secondaryAnimation,
Widget child,
) => _page.animate
? super.buildTransitions(context, animation, secondaryAnimation, child)
: child;
) => super.buildTransitions(
context,
_page.animate ? animation : kAlwaysCompleteAnimation,
secondaryAnimation,
child,
);
}
/// Opens a result in its workspace's detail pane, or an ordinary pushed route.

View File

@@ -8,7 +8,6 @@ import 'package:flutter_hooks/flutter_hooks.dart';
import '../theme/theme.dart';
import 'ios_glass_navigation_button.dart';
import 'native_route_controls.dart';
/// A native iOS glass capsule for a short navigation-bar text action.
class IosGlassNavigationAction extends HookWidget {
@@ -44,9 +43,6 @@ class IosGlassNavigationAction extends HookWidget {
@override
Widget build(BuildContext context) {
assert(defaultTargetPlatform == TargetPlatform.iOS);
if (!useNativeRouteControlsVisible(context)) {
return SizedBox(width: width, height: height);
}
return HookBuilder(builder: _buildNative);
}

View File

@@ -9,7 +9,6 @@ import 'package:flutter/services.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import '../theme/theme.dart';
import 'native_route_controls.dart';
/// The navigation glyph displayed by [IosGlassNavigationButton].
enum IosGlassNavigationIcon {
@@ -122,10 +121,6 @@ class IosGlassNavigationButton extends HookWidget {
@override
Widget build(BuildContext context) {
assert(defaultTargetPlatform == TargetPlatform.iOS);
if (!useNativeRouteControlsVisible(context)) {
return SizedBox(width: width, height: height);
}
final native = HookBuilder(builder: _buildNative);
return Tooltip(
message: semanticLabel,

View File

@@ -5,21 +5,25 @@ import 'package:flutter_hooks/flutter_hooks.dart';
/// Keeps native controls mounted for opaque sheets and their own exit motion.
/// Other covering Flutter routes suppress them to avoid platform-view bleed.
/// Must be called unconditionally from a hook widget's build method.
/// Used by Home's native-controls gate, the Channels route-currency sync and
/// `IosMessageCreateButton`. Rebuilds only when the visibility inputs change,
/// not on every animation frame. Must be called unconditionally from a hook
/// widget's build method.
bool useNativeRouteControlsVisible(BuildContext context) {
final route = ModalRoute.of(context);
final coveringProgress = useAnimation(
route?.secondaryAnimation ?? kAlwaysDismissedAnimation,
final uncovered = useListenableSelector(
route?.secondaryAnimation,
() => (route?.secondaryAnimation?.value ?? 0) == 0,
);
final reversing = useListenableSelector(
route?.animation,
() => route?.animation?.status == AnimationStatus.reverse,
);
final sheets = route == null ? null : BottomUpPageRoute.sheetsAbove(route);
useListenable(sheets);
useListenable(route?.animation);
if ((sheets?.value ?? 0) > 0) {
return true;
}
final exiting =
route != null &&
!route.isActive &&
route.animation?.status == AnimationStatus.reverse;
return ((route?.isCurrent ?? true) || exiting) && coveringProgress == 0;
final exiting = route != null && !route.isActive && reversing;
return ((route?.isCurrent ?? true) || exiting) && uncovered;
}

View File

@@ -62,6 +62,39 @@ void main() {
);
}
testWidgets('a wide thread push slides the outgoing chat on iOS', (
tester,
) async {
tester.view.devicePixelRatio = 1;
tester.view.physicalSize = const Size(1000, 800);
addTearDown(tester.view.reset);
final controller = ConversationPaneController();
addTearDown(controller.dispose);
await tester.pumpWidget(
ProviderScope(
child: MaterialApp(
theme: ThemeData(platform: TargetPlatform.iOS),
home: AdaptiveConversationPane(
controller: controller,
list: const Text('Chat list'),
),
),
),
);
controller.open('one', (_) => const _Conversation());
await tester.pumpAndSettle();
final settled = tester.getTopLeft(find.text('Conversation')).dx;
await tester.tap(find.text('Thread'));
await tester.pump();
await tester.pump(const Duration(milliseconds: 150));
expect(
tester.getTopLeft(find.text('Conversation')).dx,
lessThan(settled),
reason: 'the covered chat keeps the platform parallax',
);
await tester.pumpAndSettle();
});
testWidgets(
'wide chat switches retain the native header but reset chat state',
(tester) async {

View File

@@ -1,10 +1,14 @@
import 'dart:async';
import 'package:buzz/shared/widgets/bottom_up_page_route.dart';
import 'package:buzz/shared/widgets/ios_glass_navigation_action.dart';
import 'package:buzz/shared/widgets/ios_glass_navigation_button.dart';
import 'package:buzz/shared/widgets/ios_message_create_button.dart';
import 'package:buzz/shared/widgets/native_route_controls.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
@@ -25,153 +29,165 @@ void main() {
);
});
testWidgets('covered glass controls release their native channels', (
tester,
) async {
final messenger = binding.defaultBinaryMessenger;
final navigator = GlobalKey<NavigatorState>();
final label = ValueNotifier('Original');
addTearDown(label.dispose);
final dispatcher = tester.binding.platformDispatcher;
dispatcher.platformBrightnessTestValue = Brightness.light;
addTearDown(dispatcher.clearPlatformBrightnessTestValue);
final channels = <String, MethodChannel>{};
final disposed = <int>[];
final calls = <({MethodChannel channel, MethodCall call})>[];
final pressed = <String>[];
addTearDown(() {
for (final channel in channels.values) {
messenger.setMockMethodCallHandler(channel, null);
}
});
messenger.setMockMethodCallHandler(SystemChannels.platform_views, (
call,
) async {
if (call.method == 'create') {
final args = call.arguments as Map;
expect(args['viewType'], IosGlassNavigationButton.viewType);
final params =
const StandardMessageCodec().decodeMessage(
ByteData.sublistView(args['params'] as Uint8List),
)
as Map;
final channel = MethodChannel('${args['viewType']}/${args['id']}');
channels[params['accessibilityLabel'] as String] = channel;
messenger.setMockMethodCallHandler(channel, (call) async {
calls.add((channel: channel, call: call));
return null;
});
} else if (call.method == 'dispose') {
disposed.add(call.arguments as int);
}
return null;
});
testWidgets(
'covered glass controls stay mounted; create control releases its channel',
(tester) async {
final messenger = binding.defaultBinaryMessenger;
final navigator = GlobalKey<NavigatorState>();
final label = ValueNotifier('Original');
addTearDown(label.dispose);
final dispatcher = tester.binding.platformDispatcher;
dispatcher.platformBrightnessTestValue = Brightness.light;
addTearDown(dispatcher.clearPlatformBrightnessTestValue);
final channels = <String, MethodChannel>{};
final disposed = <int>[];
final calls = <({MethodChannel channel, MethodCall call})>[];
final pressed = <String>[];
addTearDown(() {
for (final channel in channels.values) {
messenger.setMockMethodCallHandler(channel, null);
}
});
messenger.setMockMethodCallHandler(SystemChannels.platform_views, (
call,
) async {
if (call.method == 'create') {
final args = call.arguments as Map;
expect(args['viewType'], IosGlassNavigationButton.viewType);
final params =
const StandardMessageCodec().decodeMessage(
ByteData.sublistView(args['params'] as Uint8List),
)
as Map;
final channel = MethodChannel('${args['viewType']}/${args['id']}');
channels[params['accessibilityLabel'] as String] = channel;
messenger.setMockMethodCallHandler(channel, (call) async {
calls.add((channel: channel, call: call));
return null;
});
} else if (call.method == 'dispose') {
disposed.add(call.arguments as int);
}
return null;
});
await tester.pumpWidget(
ProviderScope(
child: MaterialApp(
navigatorKey: navigator,
theme: ThemeData.light(),
darkTheme: ThemeData.dark(),
themeAnimationDuration: Duration.zero,
home: Scaffold(
body: ValueListenableBuilder<String>(
valueListenable: label,
builder: (context, value, _) => Row(
children: [
IosGlassNavigationButton(
icon: IosGlassNavigationIcon.more,
semanticLabel: 'Button $value',
onPressed: () => pressed.add('button $value'),
),
IosGlassNavigationAction(
label: 'Action $value',
onPressed: () => pressed.add('action $value'),
),
IosMessageCreateButton(
accessibilityLabel: 'Create $value',
actions: [
(
label: value,
symbol: 'plus',
onPressed: () => pressed.add('menu $value'),
),
],
),
],
await tester.pumpWidget(
ProviderScope(
child: MaterialApp(
navigatorKey: navigator,
theme: ThemeData.light(),
darkTheme: ThemeData.dark(),
themeAnimationDuration: Duration.zero,
home: Scaffold(
body: ValueListenableBuilder<String>(
valueListenable: label,
builder: (context, value, _) => Row(
children: [
IosGlassNavigationButton(
icon: IosGlassNavigationIcon.more,
semanticLabel: 'Button $value',
onPressed: () => pressed.add('button $value'),
),
IosGlassNavigationAction(
label: 'Action $value',
onPressed: () => pressed.add('action $value'),
),
IosMessageCreateButton(
accessibilityLabel: 'Create $value',
actions: [
(
label: value,
symbol: 'plus',
onPressed: () => pressed.add('menu $value'),
),
],
),
],
),
),
),
),
),
),
);
await tester.pumpAndSettle();
expect(channels, hasLength(3));
final original = channels.values.toList();
Future<void> pressControls(String label) async {
for (final kind in ['Button', 'Action', 'Create']) {
await messenger.handlePlatformMessage(
channels['$kind $label']!.name,
const StandardMethodCodec().encodeMethodCall(
kind == 'Create'
? const MethodCall('menuAction', 0)
: const MethodCall('pressed'),
),
(_) {},
);
);
await tester.pumpAndSettle();
expect(channels, hasLength(3));
Future<void> pressControls(String label) async {
for (final kind in ['Button', 'Action', 'Create']) {
await messenger.handlePlatformMessage(
channels['$kind $label']!.name,
const StandardMethodCodec().encodeMethodCall(
kind == 'Create'
? const MethodCall('menuAction', 0)
: const MethodCall('pressed'),
),
(_) {},
);
}
}
}
await pressControls('Original');
expect(pressed, ['button Original', 'action Original', 'menu Original']);
pressed.clear();
navigator.currentState!.push(
DialogRoute<void>(
context: navigator.currentContext!,
builder: (_) => const AlertDialog(content: Text('Covering dialog')),
),
);
await tester.pumpAndSettle();
expect(find.byType(UiKitView), findsNothing);
expect(
disposed,
unorderedEquals(
original.map((channel) => int.parse(channel.name.split('/').last)),
),
);
calls.clear();
dispatcher.platformBrightnessTestValue = Brightness.dark;
label.value = 'Updated';
await tester.pumpAndSettle();
expect(calls, isEmpty, reason: 'covered controls must not send updates');
await pressControls('Original');
expect(pressed, isEmpty, reason: 'disposed controls have no handlers');
navigator.currentState!.pop();
await tester.pumpAndSettle();
expect(channels, hasLength(6));
final restored = channels.values.skip(3);
expect(
calls
await pressControls('Original');
expect(pressed, ['button Original', 'action Original', 'menu Original']);
pressed.clear();
final button = channels['Button Original']!;
final action = channels['Action Original']!;
final create = channels['Create Original']!;
navigator.currentState!.push(
DialogRoute<void>(
context: navigator.currentContext!,
builder: (_) => const AlertDialog(content: Text('Covering dialog')),
),
);
await tester.pumpAndSettle();
expect(find.byType(UiKitView), findsNWidgets(2));
expect(disposed, [int.parse(create.name.split('/').last)]);
calls.clear();
dispatcher.platformBrightnessTestValue = Brightness.dark;
label.value = 'Updated';
await tester.pumpAndSettle();
final darkUpdates = calls
.where(
(entry) =>
entry.call.method == 'setAppearance' &&
(entry.call.arguments as Map)['brightness'] == 'dark',
)
.map((entry) => entry.channel),
unorderedEquals(restored),
);
expect(
tester
.widgetList<UiKitView>(find.byType(UiKitView))
.map((view) => (view.creationParams as Map)['accessibilityLabel']),
['Button Updated', 'Action Updated', 'Create Updated'],
);
await pressControls('Updated');
expect(pressed, ['button Updated', 'action Updated', 'menu Updated']);
await tester.pumpWidget(const SizedBox());
debugDefaultTargetPlatformOverride = null;
});
.map((entry) => entry.channel);
expect(
darkUpdates,
unorderedEquals([button, action]),
reason: 'covered glass controls stay mounted and keep updating',
);
expect(
calls.where((entry) => entry.channel == create),
isEmpty,
reason: 'the unmounted create control must not receive updates',
);
navigator.currentState!.pop();
await tester.pumpAndSettle();
expect(channels, hasLength(4));
expect(disposed, hasLength(1));
expect(find.byType(UiKitView), findsNWidgets(3));
for (final channel in [button, action]) {
await messenger.handlePlatformMessage(
channel.name,
const StandardMethodCodec().encodeMethodCall(
const MethodCall('pressed'),
),
(_) {},
);
}
await messenger.handlePlatformMessage(
channels['Create Updated']!.name,
const StandardMethodCodec().encodeMethodCall(
const MethodCall('menuAction', 0),
),
(_) {},
);
expect(pressed, ['button Updated', 'action Updated', 'menu Updated']);
await tester.pumpWidget(const SizedBox());
debugDefaultTargetPlatformOverride = null;
},
);
for (final bottomUp in [true, false]) {
testWidgets(
@@ -231,17 +247,19 @@ void main() {
await tester.pump();
expect(
nativeViews,
bottomUp ? findsNWidgets(3) : findsNothing,
reason: 'sheets cover mounted controls; other routes suppress them',
bottomUp ? findsNWidgets(3) : findsNWidgets(2),
reason:
'sheets cover mounted controls; other routes suppress only '
'the create control',
);
expect(tester.getSize(controls), initialSize);
await tester.pump(const Duration(milliseconds: 100));
expect(nativeViews, bottomUp ? findsNWidgets(3) : findsNothing);
expect(nativeViews, bottomUp ? findsNWidgets(3) : findsNWidgets(2));
expect(
find.byWidgetPredicate(
(w) => w is UiKitView && w.viewType == 'buzz/navigation_glass',
),
bottomUp ? findsNWidgets(4) : findsOneWidget,
bottomUp ? findsNWidgets(4) : findsNWidgets(3),
reason: 'incoming control stays visible',
);
if (bottomUp) {
@@ -264,7 +282,7 @@ void main() {
await tester.pump(const Duration(milliseconds: 100));
expect(
nativeViews,
bottomUp ? findsNWidgets(3) : findsNothing,
bottomUp ? findsNWidgets(3) : findsNWidgets(2),
reason: 'sheet reveals mounted controls throughout dismissal',
);
expect(
@@ -291,4 +309,101 @@ void main() {
},
);
}
testWidgets('glass controls stay mounted under a modal bottom sheet', (
tester,
) async {
final creates = <int>[];
final disposes = <int>[];
binding.defaultBinaryMessenger.setMockMethodCallHandler(
SystemChannels.platform_views,
(call) async {
if (call.method == 'create') {
creates.add((call.arguments as Map)['id'] as int);
} else if (call.method == 'dispose') {
disposes.add(call.arguments as int);
}
return null;
},
);
final navigator = GlobalKey<NavigatorState>();
await tester.pumpWidget(
ProviderScope(
child: MaterialApp(
navigatorKey: navigator,
home: Scaffold(
body: Row(
children: [
IosGlassNavigationButton(
icon: IosGlassNavigationIcon.more,
semanticLabel: 'More',
onPressed: () {},
),
IosGlassNavigationAction(label: 'Done', onPressed: () {}),
],
),
),
),
),
);
await tester.pumpAndSettle();
expect(creates, hasLength(2));
unawaited(
showModalBottomSheet<void>(
context: navigator.currentContext!,
builder: (_) => const SizedBox(height: 200, child: Text('Sheet')),
),
);
await tester.pumpAndSettle();
expect(find.byType(UiKitView), findsNWidgets(2));
navigator.currentState!.pop();
await tester.pumpAndSettle();
expect(find.byType(UiKitView), findsNWidgets(2));
expect(creates, hasLength(2));
expect(disposes, isEmpty);
await tester.pumpWidget(const SizedBox());
debugDefaultTargetPlatformOverride = null;
});
testWidgets('route visibility rebuilds only when it changes', (tester) async {
final navigator = GlobalKey<NavigatorState>();
final builds = <bool>[];
await tester.pumpWidget(
MaterialApp(
navigatorKey: navigator,
home: HookBuilder(
builder: (context) {
builds.add(useNativeRouteControlsVisible(context));
return const SizedBox();
},
),
),
);
await tester.pumpAndSettle();
builds.clear();
navigator.currentState!.push(
MaterialPageRoute<void>(builder: (_) => const SizedBox()),
);
var frames = 0;
await tester.pump();
while (tester.binding.hasScheduledFrame) {
await tester.pump(const Duration(milliseconds: 16));
frames++;
}
navigator.currentState!.pop();
await tester.pump();
while (tester.binding.hasScheduledFrame) {
await tester.pump(const Duration(milliseconds: 16));
frames++;
}
expect(frames, greaterThan(20), reason: 'both transitions animated');
expect(builds, isNotEmpty);
expect(builds.last, isTrue);
expect(
builds.length,
lessThanOrEqualTo(6),
reason: 'visibility must not rebuild its host on every frame',
);
debugDefaultTargetPlatformOverride = null;
});
}