From 130c1e6708aaba1cf69b97d3d7b3e3fc362e2dfd Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Thu, 3 Dec 2026 21:47:57 +0000 Subject: [PATCH] Chat stack: the default, also on a wide phone or tablet; a close button where the pile was Chat stack is now the default phone chat navigation (a stored choice is kept), and on Android or iOS it stays on a wide layout (an unfolded foldable) above the active pane, where floating is ignored too. When expanded, the pile turns into a close button at its own spot and the column rises above it; while a chat is dragged that button is the remove target, replacing the separate x at the bottom. Chat widget tests start on Quick switch (they run as Android); the stack's tests choose it. Co-Authored-By: Claude Opus 5.5 --- app/lib/features/chat/chat_screen_float.dart | 5 +- app/lib/features/chat/chat_screen_stack.dart | 14 +- .../features/chat/chat_screen_workspace.dart | 2 + app/lib/features/chat/screen.dart | 2 +- .../chat/stack/chat_stack_close_target.dart | 126 ++++++++++++++++++ .../chat/stack/chat_stack_column.dart | 58 ++++---- .../chat/stack/chat_stack_motion.dart | 15 ++- .../chat/stack/chat_stack_remove_target.dart | 106 --------------- .../chat/stack/mobile_chat_navigation.dart | 19 ++- .../settings_chat_navigation_section.dart | 5 +- app/notes/chat-stack.md | 30 +++-- .../application/chat_destination_test.dart | 7 + .../application/chat_registration_test.dart | 7 + .../features/chat/flutter_test_config.dart | 10 ++ .../chat/stack/chat_stack_drag_test.dart | 12 +- .../chat/stack/chat_stack_fab_test.dart | 27 +++- .../chat/stack/chat_stack_screen_test.dart | 66 +++++++-- ...settings_chat_navigation_section_test.dart | 17 +-- 18 files changed, 344 insertions(+), 184 deletions(-) create mode 100644 app/lib/features/chat/stack/chat_stack_close_target.dart delete mode 100644 app/lib/features/chat/stack/chat_stack_remove_target.dart diff --git a/app/lib/features/chat/chat_screen_float.dart b/app/lib/features/chat/chat_screen_float.dart index ec2102e3..c38fdb75 100644 --- a/app/lib/features/chat/chat_screen_float.dart +++ b/app/lib/features/chat/chat_screen_float.dart @@ -67,8 +67,11 @@ mixin _ChatScreenFloat on State, _ChatScreenWorkspace { /// Called from build: a change between a phone and a wide layout moves /// the floating chats between panes and windows after the frame. + @override void _trackFloatLayout() { - _phoneLayout = !showsListBesideDetail(context); + // A phone-width window, or the Chat stack on a wide phone or tablet + // layout: both navigate one chat at a time and ignore floating. + _phoneLayout = !showsListBesideDetail(context) || _stacked(context); if (widget.windows == null) return; final phone = _phoneIgnoresFloat; if (phone == _builtPhoneFloat) return; diff --git a/app/lib/features/chat/chat_screen_stack.dart b/app/lib/features/chat/chat_screen_stack.dart index 9597a65e..291501b5 100644 --- a/app/lib/features/chat/chat_screen_stack.dart +++ b/app/lib/features/chat/chat_screen_stack.dart @@ -6,6 +6,12 @@ part of 'screen.dart'; /// workspace's panes, the same open chats the server syncs; choosing one /// opens it as a tap on its list row does, Add chat is the pane menu's Add /// chat pane, and removing one closes its pane. +/// Whether this is a phone or tablet (Android or iOS, also a browser on one). +bool chatStackOnMobile() => switch (defaultTargetPlatform) { + TargetPlatform.android || TargetPlatform.iOS => true, + _ => false, +}; + mixin _ChatScreenStack on State, _ChatScreenWorkspace { final LayerLink _stackLink = LayerLink(); @@ -15,10 +21,14 @@ mixin _ChatScreenStack on State, _ChatScreenWorkspace { MobileChatNavigationController get _navigation => MobileChatNavigationController.instance; - /// Whether this layout navigates with the stack rather than the peek. + /// Whether this layout navigates with the stack rather than the peek: on + /// a phone-width window, and on a phone or tablet at any width (an + /// unfolded foldable keeps the stack above the active pane). A wide + /// desktop or web window keeps its panes alone. @override bool _stacked(BuildContext context) => - _navigation.stack && !showsListBesideDetail(context); + _navigation.stack && + (!showsListBesideDetail(context) || chatStackOnMobile()); /// Gives the active pane the stack's spot. @override diff --git a/app/lib/features/chat/chat_screen_workspace.dart b/app/lib/features/chat/chat_screen_workspace.dart index 5e2646ba..82882e0e 100644 --- a/app/lib/features/chat/chat_screen_workspace.dart +++ b/app/lib/features/chat/chat_screen_workspace.dart @@ -514,10 +514,12 @@ mixin _ChatScreenWorkspace on State { Widget _stackScope(BuildContext context, bool active, Widget child); Widget _stackOverlay(); MobileChatNavigationController get _navigation; + void _trackFloatLayout(); Widget _workspaceView() => ListenableBuilder( listenable: _navigation, builder: (context, _) { + _trackFloatLayout(); final stacked = _stacked(context); final workspace = _tiledWorkspace(context, stacked: stacked); if (!stacked) return workspace; diff --git a/app/lib/features/chat/screen.dart b/app/lib/features/chat/screen.dart index 6599be8b..14a77dc1 100644 --- a/app/lib/features/chat/screen.dart +++ b/app/lib/features/chat/screen.dart @@ -14,7 +14,7 @@ import 'dart:async'; import '../../ui/motion/motion.dart'; import '../../ui/motion/container_transform_source.dart'; -import 'package:flutter/foundation.dart' show setEquals; +import 'package:flutter/foundation.dart' show defaultTargetPlatform, setEquals; import 'package:flutter/material.dart'; import 'package:flutter/scheduler.dart'; import 'package:flutter/services.dart'; diff --git a/app/lib/features/chat/stack/chat_stack_close_target.dart b/app/lib/features/chat/stack/chat_stack_close_target.dart new file mode 100644 index 00000000..2a73127b --- /dev/null +++ b/app/lib/features/chat/stack/chat_stack_close_target.dart @@ -0,0 +1,126 @@ +import 'package:flutter/material.dart'; + +import '../../../ui/theme/app_design_tokens.dart'; +import 'chat_stack_disc.dart'; + +/// How near the close button's centre a dragged chat's pointer counts as +/// over it: a little past its rim, as a thumb covers what it drags, and +/// short of the first chat's slot a pitch above. +const double kChatStackRemoveReach = kChatStackSlot * .7; + +/// How much the button grows while a dragged chat is over it. +const double chatStackRemoveGrowth = 1.2; + +/// The open stack's close button, exactly where the pile was: the pile +/// turns into a "×" as the column rises above it, and a tap folds the +/// column back. +/// +/// While a chat is dragged it is also the remove target: its "×" turns the +/// error colour ([armed]), and with the chat over it ([hover]) it grows and +/// fills with the error colour. Dropping there is decided from the +/// pointer's position, not by this widget. +/// +/// Everything moves through transitions (fade, turn, scale, decoration), so +/// opening and dragging repaint it without rebuilding. +class ChatStackCloseTarget extends StatelessWidget { + const ChatStackCloseTarget({ + super.key, + required this.open, + required this.armed, + required this.hover, + required this.reduced, + required this.onClose, + }); + + static const label = 'Close chats'; + + /// 0 folded (the pile shows), 1 open. + final Animation open; + + /// 0 at rest, 1 while a chat is dragged. + final Animation armed; + + /// 0 idle, 1 with a dragged chat over it. + final Animation hover; + + /// Fades only: no turn, no growth. + final bool reduced; + final VoidCallback onClose; + + @override + Widget build(BuildContext context) { + final tokens = AppDesignTokens.of(context); + final scheme = Theme.of(context).colorScheme; + final dark = Theme.of(context).brightness == Brightness.dark; + final shape = chatStackShape(tokens); + final side = tokens.flat + ? tokens.frameSide ?? BorderSide(color: scheme.outlineVariant) + : BorderSide.none; + final idle = ShapeDecoration( + color: tokens.panelFill( + scheme, + dark ? scheme.surfaceContainerHighest : scheme.surface, + ), + shape: shape.copyWith(side: side), + shadows: tokens.flat ? null : chatStackShadows(scheme), + ); + final hot = ShapeDecoration( + color: scheme.error, + shape: shape.copyWith( + side: tokens.flat ? side.copyWith(color: scheme.error) : side, + ), + shadows: tokens.flat ? null : chatStackShadows(scheme), + ); + Widget icon(Color color, Animation opacity) => FadeTransition( + opacity: opacity, + child: Icon(Icons.close, color: color), + ); + Widget button = DecoratedBoxTransition( + decoration: DecorationTween(begin: idle, end: hot).animate(hover), + child: SizedBox.square( + dimension: kChatStackDisc, + child: Stack( + alignment: Alignment.center, + children: [ + icon(scheme.onSurfaceVariant, ReverseAnimation(armed)), + icon(scheme.error, armed), + icon(scheme.onError, hover), + ], + ), + ), + ); + final shown = open.drive(CurveTween(curve: Curves.easeOutCubic)); + if (!reduced) { + button = ScaleTransition( + scale: Tween( + begin: 1, + end: chatStackRemoveGrowth, + ).chain(CurveTween(curve: Curves.easeOutBack)).animate(hover), + child: button, + ); + // The pile's top avatar turns into the "×" a quarter turn. + button = RotationTransition( + turns: Tween(begin: -.25, end: 0).animate(shown), + child: ScaleTransition( + scale: Tween(begin: .6, end: 1).animate(shown), + child: button, + ), + ); + } + return Semantics( + container: true, + button: true, + label: label, + onTap: onClose, + child: GestureDetector( + behavior: HitTestBehavior.opaque, + excludeFromSemantics: true, + onTap: onClose, + child: FadeTransition( + opacity: shown, + child: Center(child: button), + ), + ), + ); + } +} diff --git a/app/lib/features/chat/stack/chat_stack_column.dart b/app/lib/features/chat/stack/chat_stack_column.dart index 1b70ddf4..c4ab76e0 100644 --- a/app/lib/features/chat/stack/chat_stack_column.dart +++ b/app/lib/features/chat/stack/chat_stack_column.dart @@ -1,5 +1,3 @@ -import 'dart:math' as math; - import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -9,13 +7,14 @@ import 'chat_stack_disc.dart'; import 'chat_stack_drag.dart'; import 'chat_stack_entry.dart'; import 'chat_stack_motion.dart'; -import 'chat_stack_remove_target.dart'; +import 'chat_stack_close_target.dart'; /// The chat stack fanned out: a scrim over the screen and the open chats in /// a column rising from the stack's own slot, each avatar with its name in a /// small pill beside it, and Add chat at the top. /// -/// Item 0 sits exactly on the collapsed stack, nearest the thumb. The chats +/// The stack's own slot turns into a close button ([ChatStackCloseTarget]); +/// item 0 sits a pitch above it, nearest the thumb. The chats /// keep the open-chat order (the order the server syncs), so a chat keeps /// its place in the column from one visit to the next; the chat on screen /// wears a ring in its colour. Add chat is last, at the top: the reachable @@ -24,7 +23,8 @@ import 'chat_stack_remove_target.dart'; /// /// A short hold lifts a chat ([ChatStackDrag]): dragged up or down it /// reorders the open chats, the others sliding aside to open its slot; -/// dropped on the "×" that comes in at the bottom it leaves them. Add chat +/// dropped on the close button (armed as a remove target while dragging) +/// it leaves them. Add chat /// stays put. The same moves are semantic actions on each chat. /// /// Nothing here rebuilds per frame: every item moves through @@ -168,7 +168,8 @@ class _ChatStackColumnState extends State builder: (context, constraints) { final size = constraints.biggest; final count = widget.motion.count; - final height = (count - 1) * kChatStackPitch + kChatStackSlot; + // The stack's own slot (the close button) and the items above it. + final height = count * kChatStackPitch + kChatStackSlot; final top = media.padding.top + 8; final available = anchor.bottom - top; final fits = height <= available; @@ -184,18 +185,23 @@ class _ChatStackColumnState extends State ..sort((a, b) => (depths[b] ?? 99).compareTo(depths[a] ?? 99)); final lifted = _entries.indexWhere((e) => e.paneId == _drag.lifted); if (lifted >= 0) order.add(order.removeAt(order.indexOf(lifted))); - // The remove target: centred in the band below the stack's slot - // (over the composer), clear of the safe area. - const r = kChatStackRemoveSize / 2; - final floor = size.height - media.padding.bottom; - final removeCenter = Offset( - size.width / 2, - math.max( - anchor.bottom + 4, - math.min((anchor.bottom + floor) / 2, floor - r - 8), + // The close button takes the pile's place; while a chat is dragged + // it is the remove target. + _removeCenter = anchor.center; + final close = Positioned.fromRect( + key: const ValueKey('chat-stack-close'), + rect: anchor, + child: IgnorePointer( + ignoring: _drag.lifted != null, + child: ChatStackCloseTarget( + open: widget.motion.close, + armed: _drag.removeShown, + hover: _drag.hover, + reduced: _drag.reduced, + onClose: widget.onDismiss, + ), ), ); - _removeCenter = removeCenter; final items = ChatStackColumnItems( motion: widget.motion, entries: _entries, @@ -226,24 +232,15 @@ class _ChatStackColumnState extends State color: scheme.scrim.withValues(alpha: dark ? .5 : .32), dismissible: true, onDismiss: widget.onDismiss, - semanticsLabel: 'Close chats', + semanticsLabel: 'Dismiss', ), ), ), - // Under the column: a chat dragged onto it is drawn over it. - if (widget.onRemove != null) - Positioned( - left: removeCenter.dx - r, - top: removeCenter.dy - r, - width: kChatStackRemoveSize, - height: kChatStackRemoveSize, - child: ChatStackRemoveTarget( - shown: _drag.removeShown, - hover: _drag.hover, - reduced: _drag.reduced, - ), - ), + // A dragged chat is drawn over the button (it shrinks into + // it); otherwise the button is on top, to take its tap. + if (_drag.lifted != null) close, PositionedDirectional( + key: const ValueKey('chat-stack-column'), end: endInset, bottom: size.height - anchor.bottom, top: top, @@ -266,6 +263,7 @@ class _ChatStackColumnState extends State ), ), ), + if (_drag.lifted == null) close, ], ), ), diff --git a/app/lib/features/chat/stack/chat_stack_motion.dart b/app/lib/features/chat/stack/chat_stack_motion.dart index 25653705..8d8bada3 100644 --- a/app/lib/features/chat/stack/chat_stack_motion.dart +++ b/app/lib/features/chat/stack/chat_stack_motion.dart @@ -20,9 +20,10 @@ const Curve chatStackRise = Cubic(.22, 1.18, .36, 1); const Curve chatStackFold = Curves.easeInCubic; /// Every animation the open column reads, derived once from one controller -/// when the items change (never per frame). Item 0 is nearest the thumb; the -/// column rises from there, each item starting a little after the one below -/// it, and folds back top first. +/// when the items change (never per frame). Item 0 is nearest the thumb, a +/// pitch above the stack's slot (where the close button is); the column +/// rises from there, each item starting a little after the one below it, +/// and folds back top first. class ChatStackMotion { ChatStackMotion({ required Animation parent, @@ -31,13 +32,16 @@ class ChatStackMotion { required bool rtl, }) : count = depths.length { scrim = _curve(parent, const Interval(0, .7, curve: Curves.easeOut)); + close = reduced ? parent : _curve(parent, const Interval(0, .6)); final span = count <= 1 ? 1.0 : .62; final step = count <= 1 ? 0.0 : (1 - span) / (count - 1); for (var i = 0; i < count; i++) { final start = i * step; final end = math.min(1.0, start + span); final depth = depths[i]; - final to = chatStackColumnPose(i, kChatStackPitch); + // The stack's own slot holds the close button; the column starts a + // pitch above it. + final to = chatStackColumnPose(i + 1, kChatStackPitch); final layer = chatStackLayers[depth ?? chatStackLayers.length - 1]; target.add(to); if (reduced) { @@ -75,6 +79,9 @@ class ChatStackMotion { final int count; final bool reduced; late final Animation scrim; + + /// The close button taking the pile's place. + late final Animation close; final List from = []; final List target = []; final List> move = []; diff --git a/app/lib/features/chat/stack/chat_stack_remove_target.dart b/app/lib/features/chat/stack/chat_stack_remove_target.dart deleted file mode 100644 index 72123b52..00000000 --- a/app/lib/features/chat/stack/chat_stack_remove_target.dart +++ /dev/null @@ -1,106 +0,0 @@ -import 'package:flutter/material.dart'; - -import '../../../ui/theme/app_design_tokens.dart'; -import 'chat_stack_disc.dart'; - -/// The remove target's diameter: a little larger than an item, so it reads -/// as a destination rather than another chat. -const double kChatStackRemoveSize = kChatStackSlot + 8; - -/// How near its centre a finger counts as over the target: past its rim, -/// as a thumb covers what it drags. -const double kChatStackRemoveReach = kChatStackRemoveSize * .8; - -/// How much the target grows while a chat is over it. -const double chatStackRemoveGrowth = 1.2; - -/// The "×" a dragged chat is dropped on to leave the open chats: a circle -/// (the design's square under a flat design) that comes in when a drag -/// starts and fills with the error colour while a chat is over it. It takes -/// no input and says nothing to assistive technology: dropping is decided -/// from the pointer's position, and the column's items offer the same -/// removal as an action. -/// -/// Everything moves through transitions (fade, slide, scale, decoration), -/// so a drag repaints it without rebuilding. -class ChatStackRemoveTarget extends StatelessWidget { - const ChatStackRemoveTarget({ - super.key, - required this.shown, - required this.hover, - required this.reduced, - }); - - /// 0 hidden, 1 in place. - final Animation shown; - - /// 0 idle, 1 with a chat over it. - final Animation hover; - - /// Fades only: no slide in, no growth. - final bool reduced; - - @override - Widget build(BuildContext context) { - final tokens = AppDesignTokens.of(context); - final scheme = Theme.of(context).colorScheme; - final dark = Theme.of(context).brightness == Brightness.dark; - final shape = chatStackShape(tokens); - final side = tokens.flat - ? tokens.frameSide ?? BorderSide(color: scheme.outlineVariant) - : BorderSide.none; - final idle = ShapeDecoration( - color: tokens.panelFill( - scheme, - dark ? scheme.surfaceContainerHighest : scheme.surface, - ), - shape: shape.copyWith(side: side), - shadows: tokens.flat ? null : chatStackShadows(scheme), - ); - final hot = ShapeDecoration( - color: scheme.error, - shape: shape.copyWith( - side: tokens.flat ? side.copyWith(color: scheme.error) : side, - ), - shadows: tokens.flat ? null : chatStackShadows(scheme), - ); - final curve = shown.drive(CurveTween(curve: Curves.easeOutCubic)); - Widget target = DecoratedBoxTransition( - decoration: DecorationTween(begin: idle, end: hot).animate(hover), - child: SizedBox.square( - dimension: kChatStackRemoveSize, - child: Stack( - alignment: Alignment.center, - children: [ - Icon(Icons.close, color: scheme.onSurfaceVariant), - FadeTransition( - opacity: hover, - child: Icon(Icons.close, color: scheme.onError), - ), - ], - ), - ), - ); - if (!reduced) { - target = ScaleTransition( - scale: Tween( - begin: 1, - end: chatStackRemoveGrowth, - ).chain(CurveTween(curve: Curves.easeOutBack)).animate(hover), - child: target, - ); - target = SlideTransition( - position: Tween( - begin: const Offset(0, .5), - end: Offset.zero, - ).animate(curve), - child: target, - ); - } - return IgnorePointer( - child: ExcludeSemantics( - child: FadeTransition(opacity: curve, child: target), - ), - ); - } -} diff --git a/app/lib/features/chat/stack/mobile_chat_navigation.dart b/app/lib/features/chat/stack/mobile_chat_navigation.dart index b8802dc1..aca18839 100644 --- a/app/lib/features/chat/stack/mobile_chat_navigation.dart +++ b/app/lib/features/chat/stack/mobile_chat_navigation.dart @@ -3,7 +3,8 @@ import 'package:shared_preferences/shared_preferences.dart'; const mobileChatNavigationKey = 'pipelines.mobile-chat-navigation.v1'; -/// How a phone-width layout moves between the open chats. +/// How a phone-width layout (and any layout on a phone or tablet, an unfolded +/// foldable too, for the Chat stack) moves between the open chats. enum MobileChatNavigation { quickSwitch( 'Quick switch', @@ -59,7 +60,11 @@ class MobileChatNavigationController extends ChangeNotifier { static final instance = MobileChatNavigationController(); final MobileChatNavigationStore _store; - MobileChatNavigation _value = MobileChatNavigation.quickSwitch; + + /// Without a stored choice, the Chat stack. + static const fallback = MobileChatNavigation.chatStack; + + MobileChatNavigation _value = fallback; int _revision = 0; bool _disposed = false; bool saveFailed = false; @@ -91,6 +96,16 @@ class MobileChatNavigationController extends ChangeNotifier { notifyListeners(); } + /// Sets [mode] without saving it (a test's starting point). + @visibleForTesting + void debugUse(MobileChatNavigation mode) { + _revision++; + saveFailed = false; + if (mode == _value) return; + _value = mode; + notifyListeners(); + } + @override void dispose() { _disposed = true; diff --git a/app/lib/features/settings/settings_chat_navigation_section.dart b/app/lib/features/settings/settings_chat_navigation_section.dart index 81e611de..03d1e8d3 100644 --- a/app/lib/features/settings/settings_chat_navigation_section.dart +++ b/app/lib/features/settings/settings_chat_navigation_section.dart @@ -27,8 +27,9 @@ class SettingsChatNavigationSection extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.stretch, children: [ const Text( - 'Saved on this device. Applies on a phone-width window; a wide ' - 'window keeps the chat list beside the chats.', + 'Saved on this device. Applies on a phone-width window; the ' + 'Chat stack also stays on a wide phone or tablet layout (an ' + 'unfolded foldable), beside the chat list.', ), if (navigation.saveFailed) Text( diff --git a/app/notes/chat-stack.md b/app/notes/chat-stack.md index 0ffac150..13f3d3c1 100644 --- a/app/notes/chat-stack.md +++ b/app/notes/chat-stack.md @@ -2,11 +2,16 @@ ## Setting -Settings → Mobile chat navigation: Quick switch (default, the next chat's -peek under the current one) or Chat stack. Per device -(`pipelines.mobile-chat-navigation.v1`, `MobileChatNavigationController`, -restored in `bootstrap.dart`), applied live, and only on a phone-width layout -(`!showsListBesideDetail`). A wide window keeps its panes and shows no stack. +Settings → Mobile chat navigation: Chat stack (the default without a stored +choice) or Quick switch (the next chat's peek under the current one). Per +device (`pipelines.mobile-chat-navigation.v1`, `MobileChatNavigationController`, +restored in `bootstrap.dart`; a stored choice is kept), applied live. It +applies on a phone-width layout (`!showsListBesideDetail`); the Chat stack +also stays on a wide layout on Android or iOS (an unfolded foldable, a +tablet, a browser on one), floating above the active pane beside the list +(`chatStackOnMobile`). A wide desktop or web window keeps its panes alone. +Widget tests run as Android: `test/features/chat/flutter_test_config.dart` +starts each chat test on Quick switch (`debugUse`); the stack's tests pick it. ## Behaviour @@ -19,11 +24,11 @@ restored in `bootstrap.dart`), applied live, and only on a phone-width layout (flat designs: a primary-colour frame instead). Dragged up or down, the others slide aside (200 ms ease-out) to open its slot, with a selection tick per slot; dropping commits through `ChatWorkspaceController.movePane` - (the pane order the server syncs as the open-chat order). A "×" fades and - slides in, centred in the band below the stack's slot (over the composer, - above the safe area); over it (a reach of 0.8x its size around its centre) - it grows 1.2x and fills with the error colour, and the chat shrinks into - it. Dropping there removes the pane with the Undo snack bar; Undo re-adds + (the pane order the server syncs as the open-chat order). The close + button at the stack's slot is the remove target while dragging: its "×" + turns the error colour, and over it (a reach of 0.7 slot around its + centre, short of item 0 a pitch above) it grows 1.2x and fills with the + error colour, and the chat shrinks into it. Dropping there removes the pane with the Undo snack bar; Undo re-adds it at its old index and keeps the chat on screen. A drop far to the side (more than 1.5 pitches) or Escape or a cancelled pointer puts it back. Add chat never lifts and is never a slot. Semantics: Move up, Move down, @@ -36,7 +41,10 @@ restored in `bootstrap.dart`), applied live, and only on a phone-width layout transcript area, just above the composer, so it never covers Send; the transcript pads its last line and Jump to latest above it. It hides while the on-screen keyboard is up (the window's view insets). -- Expanded: a scrim, and a column rising from the stack's slot. The chats keep +- Expanded: a scrim; the pile turns into a close button ("×", a quarter + turn and scale in, `ChatStackCloseTarget`) exactly where it was, so a + second tap on the same spot folds the column; the column rises from one + pitch above it. The chats keep the open-chat order bottom-up (stable positions for muscle memory); the chat on screen wears a ring in its colour; each avatar keeps its list badges (waiting, working, background tasks) and has a name pill tinted with its diff --git a/app/test/application/chat_destination_test.dart b/app/test/application/chat_destination_test.dart index aed29da1..abec0299 100644 --- a/app/test/application/chat_destination_test.dart +++ b/app/test/application/chat_destination_test.dart @@ -1,5 +1,6 @@ import 'dart:convert'; +import 'package:pipelines_app/features/chat/stack/mobile_chat_navigation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/application/app_session.dart'; @@ -29,6 +30,12 @@ Widget host(AppSession session, {String? initialSessionId}) => MaterialApp( ); void main() { + // These describe the Quick switch layout (the peek of the next chat). + setUp( + () => MobileChatNavigationController.instance.debugUse( + MobileChatNavigation.quickSwitch, + ), + ); testWidgets('nothing is requested before the shared socket is ready', ( tester, ) async { diff --git a/app/test/application/chat_registration_test.dart b/app/test/application/chat_registration_test.dart index 4a32664e..9514eacd 100644 --- a/app/test/application/chat_registration_test.dart +++ b/app/test/application/chat_registration_test.dart @@ -1,5 +1,6 @@ import 'dart:convert'; +import 'package:pipelines_app/features/chat/stack/mobile_chat_navigation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -293,6 +294,12 @@ Future replyChatHistory( } void main() { + // These describe the Quick switch layout (the peek of the next chat). + setUp( + () => MobileChatNavigationController.instance.debugUse( + MobileChatNavigation.quickSwitch, + ), + ); testWidgets( 'a wide /chat/s1 deep link shows that thread beside the list and route Back returns to /chat', (tester) async { diff --git a/app/test/features/chat/flutter_test_config.dart b/app/test/features/chat/flutter_test_config.dart index 2e3f4e32..85859eac 100644 --- a/app/test/features/chat/flutter_test_config.dart +++ b/app/test/features/chat/flutter_test_config.dart @@ -1,13 +1,23 @@ import 'dart:async'; import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/features/chat/stack/mobile_chat_navigation.dart'; /// Functional chat tests settle asynchronous state with reduced motion. Tests /// covering animation explicitly opt back in and pump known frame durations. +/// +/// Tests run as Android, where the Chat stack (the default) also shows on a +/// wide layout. Each test starts on Quick switch, the layout most of them +/// describe; the stack's own tests choose it. Future testExecutable(FutureOr Function() testMain) async { TestWidgetsFlutterBinding.ensureInitialized() .platformDispatcher .accessibilityFeaturesTestValue = const FakeAccessibilityFeatures( disableAnimations: true, ); + setUp( + () => MobileChatNavigationController.instance.debugUse( + MobileChatNavigation.quickSwitch, + ), + ); await testMain(); } diff --git a/app/test/features/chat/stack/chat_stack_drag_test.dart b/app/test/features/chat/stack/chat_stack_drag_test.dart index a97afd51..bedbbcb3 100644 --- a/app/test/features/chat/stack/chat_stack_drag_test.dart +++ b/app/test/features/chat/stack/chat_stack_drag_test.dart @@ -11,7 +11,7 @@ import 'package:pipelines_app/features/chat/screen.dart'; import 'package:pipelines_app/features/chat/stack/chat_stack_column.dart'; import 'package:pipelines_app/features/chat/stack/chat_stack_disc.dart'; import 'package:pipelines_app/features/chat/stack/chat_stack_drag.dart'; -import 'package:pipelines_app/features/chat/stack/chat_stack_remove_target.dart'; +import 'package:pipelines_app/features/chat/stack/chat_stack_close_target.dart'; import 'package:pipelines_app/features/chat/stack/mobile_chat_navigation.dart'; import 'package:pipelines_app/features/chat/workspace/chat_workspace.dart'; import 'package:pipelines_app/shell/adaptive_shell.dart'; @@ -117,7 +117,7 @@ Finder _button(WidgetTester tester, String id) { } final _add = find.byKey(const ValueKey('chat-stack-button-add')); -final _target = find.byType(ChatStackRemoveTarget); +final _target = find.byType(ChatStackCloseTarget); /// Holds [finder] until it lifts. Future _lift(WidgetTester tester, Finder finder) async { @@ -127,7 +127,7 @@ Future _lift(WidgetTester tester, Finder finder) async { } double _shown(WidgetTester tester) => - tester.widget(_target).shown.value; + tester.widget(_target).armed.value; void main() { final navigation = MobileChatNavigationController.instance; @@ -182,7 +182,7 @@ void main() { final from = tester.getCenter(_button(tester, 'b')); await gesture.moveBy(tester.getCenter(_target) - from); await tester.pumpAndSettle(); - final drag = tester.widget(_target).hover; + final drag = tester.widget(_target).hover; expect(drag.value, 1); await gesture.up(); await tester.pumpAndSettle(); @@ -308,9 +308,9 @@ void main() { await gesture.moveBy(const Offset(0, -kChatStackPitch)); await tester.pump(); expect(tester.getCenter(_button(tester, 'b')).dy, b.dy + kChatStackPitch); - // No slide: the target sits in place. + // No turn or growth: the button only fades. expect( - find.descendant(of: _target, matching: find.byType(SlideTransition)), + find.descendant(of: _target, matching: find.byType(RotationTransition)), findsNothing, ); await gesture.up(); diff --git a/app/test/features/chat/stack/chat_stack_fab_test.dart b/app/test/features/chat/stack/chat_stack_fab_test.dart index 6b7339ea..3f0ae77c 100644 --- a/app/test/features/chat/stack/chat_stack_fab_test.dart +++ b/app/test/features/chat/stack/chat_stack_fab_test.dart @@ -1,7 +1,9 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/features/chat/stack/chat_stack_close_target.dart'; import 'package:pipelines_app/features/chat/stack/chat_stack_column.dart'; +import 'package:pipelines_app/features/chat/stack/chat_stack_disc.dart'; import 'package:pipelines_app/features/chat/stack/chat_stack_entry.dart'; import 'package:pipelines_app/features/chat/stack/chat_stack_fab.dart'; import 'package:pipelines_app/features/chat/stack/chat_stack_pose.dart'; @@ -103,7 +105,8 @@ void main() { expect(find.text('Chat 0'), findsOneWidget); expect(find.text('Chat 4'), findsOneWidget); expect(find.text(ChatStackColumn.addLabel), findsOneWidget); - // Item 0 sits on the stack; each further item rises one pitch. + // The stack's slot holds the close button; item 0 sits a pitch above + // it and each further item rises one more. final first = tester.getCenter( find.byKey(const ValueKey('chat-stack-button-pane-0')), ); @@ -114,7 +117,11 @@ void main() { find.byKey(const ValueKey('chat-stack-button-add')), ); expect(first.dx, closeTo(slot.center.dx, .5)); - expect(first.dy, closeTo(slot.center.dy, .5)); + expect(first.dy, closeTo(slot.center.dy - kChatStackPitch, .5)); + expect( + tester.getCenter(find.bySemanticsLabel(ChatStackCloseTarget.label)), + slot.center, + ); expect(second.dy, lessThan(first.dy)); expect(add.dy, lessThan(second.dy)); // Outside the column. @@ -126,6 +133,22 @@ void main() { expect(harness.opened, isEmpty); }); + testWidgets('the close button where the pile was folds the column', ( + tester, + ) async { + final harness = await _pump(tester); + final slot = tester.getRect(find.byKey(const Key('chat-stack'))); + await tester.tap(find.byKey(const Key('chat-stack'))); + await _settle(tester); + await tester.tapAt(slot.center); + await tester.pump(); + expect(_state(tester).expanded, isFalse); + await _settle(tester); + expect(find.byType(ChatStackColumn), findsNothing); + expect(harness.opened, isEmpty); + expect(harness.added, 0); + }); + testWidgets('tapping a chat opens it and folds the column', (tester) async { final harness = await _pump(tester); await tester.tap(find.byKey(const Key('chat-stack'))); diff --git a/app/test/features/chat/stack/chat_stack_screen_test.dart b/app/test/features/chat/stack/chat_stack_screen_test.dart index 789a19a0..e2412cfb 100644 --- a/app/test/features/chat/stack/chat_stack_screen_test.dart +++ b/app/test/features/chat/stack/chat_stack_screen_test.dart @@ -34,6 +34,15 @@ class _Gateway extends FakeChatGateway { } } +class _Store implements MobileChatNavigationStore { + _Store(this.value); + final String? value; + @override + Future load() async => value; + @override + Future save(String value) async => true; +} + Future _pump(WidgetTester tester, Size size) async { SharedPreferences.setMockInitialValues({}); unawaited( @@ -114,14 +123,53 @@ void main() { await tester.pumpWidget(const SizedBox.shrink()); }); - testWidgets('a wide window keeps its panes and shows no stack', ( - tester, - ) async { - await _pump(tester, const Size(1280, 800)); - await tester.tap(find.byKey(const Key('chat-row-a'))); - await tester.pumpAndSettle(); - expect(_thread('a'), findsOneWidget); - expect(_stack, findsNothing); - await tester.pumpWidget(const SizedBox.shrink()); + testWidgets( + 'a wide desktop window keeps its panes and shows no stack', + variant: TargetPlatformVariant.desktop(), + (tester) async { + await _pump(tester, const Size(1280, 800)); + await tester.tap(find.byKey(const Key('chat-row-a'))); + await tester.pumpAndSettle(); + expect(_thread('a'), findsOneWidget); + expect(_stack, findsNothing); + await tester.pumpWidget(const SizedBox.shrink()); + }, + ); + + testWidgets( + 'a wide phone or tablet layout (an unfolded foldable) keeps the stack', + variant: TargetPlatformVariant({ + TargetPlatform.android, + TargetPlatform.iOS, + }), + (tester) async { + await _pump(tester, const Size(1280, 800)); + await tester.tap(find.byKey(const Key('chat-row-a'))); + await tester.pumpAndSettle(); + expect(_thread('a'), findsOneWidget); + // The list stays beside the chat, the stack floats over the pane. + expect(find.byKey(const Key('chat-row-b')), findsOneWidget); + expect(_stack.hitTestable(), findsOneWidget); + await tester.tap(_stack); + await tester.pumpAndSettle(); + await tester.tap(find.byKey(const ValueKey('chat-stack-button-add'))); + await tester.pumpAndSettle(); + await tester.tap(find.text('Beta').last); + await tester.pumpAndSettle(); + expect(find.bySemanticsLabel(chatStackLabel(2)), findsOneWidget); + await tester.pumpWidget(const SizedBox.shrink()); + }, + ); + + test('Chat stack is the default without a stored choice', () async { + final controller = MobileChatNavigationController(store: _Store(null)); + expect(controller.value, MobileChatNavigation.chatStack); + await controller.restore(); + expect(controller.value, MobileChatNavigation.chatStack); + final chosen = MobileChatNavigationController(store: _Store('quickSwitch')); + await chosen.restore(); + expect(chosen.value, MobileChatNavigation.quickSwitch); + controller.dispose(); + chosen.dispose(); }); } diff --git a/app/test/features/settings/settings_chat_navigation_section_test.dart b/app/test/features/settings/settings_chat_navigation_section_test.dart index 994de1ac..1167b8f0 100644 --- a/app/test/features/settings/settings_chat_navigation_section_test.dart +++ b/app/test/features/settings/settings_chat_navigation_section_test.dart @@ -32,19 +32,20 @@ void main() { ), ); expect(find.text(SettingsChatNavigationSection.title), findsOneWidget); - expect(controller.value, MobileChatNavigation.quickSwitch); + // Without a stored choice: the Chat stack. + expect(controller.value, MobileChatNavigation.chatStack); expect( - find.text(MobileChatNavigation.quickSwitch.description), + find.text(MobileChatNavigation.chatStack.description), findsOneWidget, ); await tester.tap( - find.byKey(const ValueKey('settings-chat-navigation-chatStack')), + find.byKey(const ValueKey('settings-chat-navigation-quickSwitch')), ); await tester.pumpAndSettle(); - expect(controller.value, MobileChatNavigation.chatStack); - expect(store.saved, 'chatStack'); + expect(controller.value, MobileChatNavigation.quickSwitch); + expect(store.saved, 'quickSwitch'); expect( - find.text(MobileChatNavigation.chatStack.description), + find.text(MobileChatNavigation.quickSwitch.description), findsOneWidget, ); @@ -52,11 +53,11 @@ void main() { final next = MobileChatNavigationController(store: store); addTearDown(next.dispose); await next.restore(); - expect(next.value, MobileChatNavigation.chatStack); + expect(next.value, MobileChatNavigation.quickSwitch); store.success = false; await tester.tap( - find.byKey(const ValueKey('settings-chat-navigation-quickSwitch')), + find.byKey(const ValueKey('settings-chat-navigation-chatStack')), ); await tester.pumpAndSettle(); expect(find.text('Could not save; applies until reload.'), findsOneWidget);