diff --git a/mobile/lib/shared/widgets/adaptive_conversation_pane.dart b/mobile/lib/shared/widgets/adaptive_conversation_pane.dart index 5a317c9cef..6183754b14 100644 --- a/mobile/lib/shared/widgets/adaptive_conversation_pane.dart +++ b/mobile/lib/shared/widgets/adaptive_conversation_pane.dart @@ -601,9 +601,12 @@ class _ConversationDetailRoute extends MaterialPageRoute { Animation animation, Animation 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. diff --git a/mobile/lib/shared/widgets/ios_glass_navigation_action.dart b/mobile/lib/shared/widgets/ios_glass_navigation_action.dart index d05b767d91..dac5da3f0e 100644 --- a/mobile/lib/shared/widgets/ios_glass_navigation_action.dart +++ b/mobile/lib/shared/widgets/ios_glass_navigation_action.dart @@ -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); } diff --git a/mobile/lib/shared/widgets/ios_glass_navigation_button.dart b/mobile/lib/shared/widgets/ios_glass_navigation_button.dart index 324d925dd2..3f27313704 100644 --- a/mobile/lib/shared/widgets/ios_glass_navigation_button.dart +++ b/mobile/lib/shared/widgets/ios_glass_navigation_button.dart @@ -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, diff --git a/mobile/lib/shared/widgets/native_route_controls.dart b/mobile/lib/shared/widgets/native_route_controls.dart index d57e8f18f0..ac7dfbeccd 100644 --- a/mobile/lib/shared/widgets/native_route_controls.dart +++ b/mobile/lib/shared/widgets/native_route_controls.dart @@ -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; } diff --git a/mobile/test/shared/widgets/adaptive_conversation_pane_test.dart b/mobile/test/shared/widgets/adaptive_conversation_pane_test.dart index 1cdc86b424..ea702ae91b 100644 --- a/mobile/test/shared/widgets/adaptive_conversation_pane_test.dart +++ b/mobile/test/shared/widgets/adaptive_conversation_pane_test.dart @@ -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 { diff --git a/mobile/test/shared/widgets/native_route_controls_test.dart b/mobile/test/shared/widgets/native_route_controls_test.dart index be5ad69d01..ac22ae8c9a 100644 --- a/mobile/test/shared/widgets/native_route_controls_test.dart +++ b/mobile/test/shared/widgets/native_route_controls_test.dart @@ -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(); - final label = ValueNotifier('Original'); - addTearDown(label.dispose); - final dispatcher = tester.binding.platformDispatcher; - dispatcher.platformBrightnessTestValue = Brightness.light; - addTearDown(dispatcher.clearPlatformBrightnessTestValue); - final channels = {}; - final disposed = []; - final calls = <({MethodChannel channel, MethodCall call})>[]; - final pressed = []; - 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(); + final label = ValueNotifier('Original'); + addTearDown(label.dispose); + final dispatcher = tester.binding.platformDispatcher; + dispatcher.platformBrightnessTestValue = Brightness.light; + addTearDown(dispatcher.clearPlatformBrightnessTestValue); + final channels = {}; + final disposed = []; + final calls = <({MethodChannel channel, MethodCall call})>[]; + final pressed = []; + 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( - 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( + 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 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 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( - 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( + 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(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 = []; + final disposes = []; + 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(); + 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( + 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(); + final builds = []; + 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(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; + }); }