diff --git a/app/lib/features/chat/workspace/chat_mobile_panes.dart b/app/lib/features/chat/workspace/chat_mobile_panes.dart index e6439428..61e338db 100644 --- a/app/lib/features/chat/workspace/chat_mobile_panes.dart +++ b/app/lib/features/chat/workspace/chat_mobile_panes.dart @@ -3,6 +3,7 @@ import 'package:flutter/semantics.dart'; import 'package:flutter/widgets.dart'; import '../conversation/chat_pane_presentation.dart'; import 'chat_peek_gesture.dart'; +import 'chat_peek_header.dart'; import 'chat_workspace_controller.dart'; /// A phone presentation only: saved split axes and ratios are left untouched. @@ -86,29 +87,51 @@ class ChatMobilePaneViewport extends StatelessWidget { final String paneId; @override - Widget build(BuildContext context) => ClipRect( - child: Semantics( - key: ValueKey('chat-peek-$paneId'), - identifier: peek ? 'chat-peek-$paneId' : null, - container: peek, - sortKey: peek ? const OrdinalSortKey(1) : null, - label: peek ? 'Expand $label' : null, - button: peek ? true : null, - onTap: peek ? onActivate : null, - child: ChatPeekGesture( + Widget build(BuildContext context) => LayoutBuilder( + builder: (context, constraints) => ClipRect( + child: Semantics( + key: ValueKey('chat-peek-$paneId'), + identifier: peek ? 'chat-peek-$paneId' : null, + container: peek, + sortKey: peek ? const OrdinalSortKey(1) : null, + label: peek ? 'Expand $label' : null, + button: peek ? true : null, onTap: peek ? onActivate : null, - child: ExcludeFocus( - excluding: peek, - child: ExcludeSemantics( - excluding: peek, - child: RepaintBoundary( - child: ChatPanePresentation( - peek: peek, - barReveal: barReveal, - fixedChromeLayout: fixedChromeLayout, - child: child, + child: ChatPeekGesture( + onTap: peek ? onActivate : null, + child: Column( + children: [ + Offstage( + offstage: !peek || fixedChromeLayout, + child: ConstrainedBox( + constraints: BoxConstraints(maxHeight: constraints.maxHeight), + child: ClipRect( + child: ExcludeSemantics( + child: ChatPeekHeader( + title: label, + onActivate: onActivate, + ), + ), + ), + ), ), - ), + Expanded( + child: ExcludeFocus( + excluding: peek, + child: ExcludeSemantics( + excluding: peek, + child: RepaintBoundary( + child: ChatPanePresentation( + peek: peek, + barReveal: barReveal, + fixedChromeLayout: fixedChromeLayout, + child: child, + ), + ), + ), + ), + ), + ], ), ), ), diff --git a/app/lib/features/chat/workspace/chat_mobile_peek_divider.dart b/app/lib/features/chat/workspace/chat_mobile_peek_divider.dart index 20143a37..1b5d78d8 100644 --- a/app/lib/features/chat/workspace/chat_mobile_peek_divider.dart +++ b/app/lib/features/chat/workspace/chat_mobile_peek_divider.dart @@ -1,6 +1,8 @@ import 'dart:math' as math; import 'package:flutter/services.dart'; -import 'package:flutter/widgets.dart'; +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import '../../../ui/adaptive/host.dart'; /// A transparent touch target centred on the active chat's coloured bottom /// border. Height is bounded by the original 20% peek and a nonzero minimum. @@ -20,6 +22,7 @@ class ChatMobilePeekDivider extends StatefulWidget { class _ChatMobilePeekDividerState extends State { double? _dragHeight; + bool _focused = false; double get _maximum => widget.available * .2; double get _minimum => math.min(48.0, _maximum); void _change(double value) { @@ -42,6 +45,7 @@ class _ChatMobilePeekDividerState extends State { onIncrease: () => _step(16), onDecrease: () => _step(-16), child: Focus( + onFocusChange: (focused) => setState(() => _focused = focused), onKeyEvent: (_, event) { if (event is! KeyDownEvent && event is! KeyRepeatEvent) { return KeyEventResult.ignored; @@ -66,7 +70,40 @@ class _ChatMobilePeekDividerState extends State { }, onVerticalDragEnd: (_) => _dragHeight = null, onVerticalDragCancel: () => _dragHeight = null, - child: const SizedBox.expand(), + child: Tooltip( + message: 'Drag to resize inactive chat', + child: Center( + child: DecoratedBox( + decoration: BoxDecoration( + color: usesCupertinoHost(context) + ? CupertinoColors.secondarySystemBackground.resolveFrom( + context, + ) + : Theme.of(context).colorScheme.surfaceContainerHigh, + borderRadius: BorderRadius.circular(8), + border: _focused + ? Border.all( + color: usesCupertinoHost(context) + ? CupertinoTheme.of(context).primaryColor + : Theme.of(context).colorScheme.primary, + ) + : null, + ), + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 8), + child: Icon( + usesCupertinoHost(context) + ? CupertinoIcons.minus + : Icons.drag_handle, + size: 18, + color: usesCupertinoHost(context) + ? CupertinoColors.secondaryLabel.resolveFrom(context) + : Theme.of(context).colorScheme.onSurfaceVariant, + ), + ), + ), + ), + ), ), ), ), diff --git a/app/lib/features/chat/workspace/chat_peek_header.dart b/app/lib/features/chat/workspace/chat_peek_header.dart new file mode 100644 index 00000000..ca3fbc90 --- /dev/null +++ b/app/lib/features/chat/workspace/chat_peek_header.dart @@ -0,0 +1,79 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import '../../../ui/adaptive/host.dart'; + +/// A named, explicit switch action above the inactive transcript. It occupies +/// space rather than obscuring the small chat's readable content. +class ChatPeekHeader extends StatelessWidget { + const ChatPeekHeader({ + super.key, + required this.title, + required this.onActivate, + }); + final String title; + final VoidCallback onActivate; + + @override + Widget build(BuildContext context) => LayoutBuilder( + builder: (context, constraints) { + final compact = constraints.maxHeight < 44; + final cupertino = usesCupertinoHost(context); + final textStyle = cupertino + ? (compact + ? CupertinoTheme.of(context).textTheme.tabLabelTextStyle + : CupertinoTheme.of(context).textTheme.textStyle) + : (compact + ? Theme.of(context).textTheme.labelMedium + : Theme.of(context).textTheme.labelLarge); + final foreground = cupertino + ? CupertinoColors.label.resolveFrom(context) + : Theme.of(context).colorScheme.onSurface; + final background = cupertino + ? CupertinoColors.secondarySystemBackground.resolveFrom(context) + : Theme.of(context).colorScheme.surfaceContainer; + final content = Row( + children: [ + Expanded( + child: Text( + title, + maxLines: 1, + overflow: TextOverflow.ellipsis, + style: textStyle?.copyWith(color: foreground), + ), + ), + const SizedBox(width: 8), + Text('Switch', style: textStyle?.copyWith(color: foreground)), + const SizedBox(width: 4), + Icon( + cupertino ? CupertinoIcons.arrow_up : Icons.arrow_upward, + color: foreground, + size: 18, + ), + ], + ); + return ColoredBox( + color: background, + child: Tooltip( + message: 'Switch to $title', + child: cupertino + ? CupertinoButton( + minimumSize: const Size(0, 44), + padding: const EdgeInsets.symmetric(horizontal: 12), + onPressed: onActivate, + child: content, + ) + : TextButton( + style: TextButton.styleFrom( + minimumSize: const Size(0, 44), + tapTargetSize: MaterialTapTargetSize.shrinkWrap, + padding: const EdgeInsets.symmetric(horizontal: 12), + shape: const RoundedRectangleBorder(), + ), + onPressed: onActivate, + child: content, + ), + ), + ); + }, + ); +} diff --git a/app/notes/mobile-peek-identity.md b/app/notes/mobile-peek-identity.md new file mode 100644 index 00000000..05af4cc1 --- /dev/null +++ b/app/notes/mobile-peek-identity.md @@ -0,0 +1,27 @@ +# Mobile peek identity and resize affordance + +The inactive mobile chat now has a persistent title and native Switch action. +The header occupies layout space above its transcript rather than covering it. +The existing Expand semantics and chat-peek-<pane-id> identifier remain, +so tapping any non-dragging area still switches and transcript drags still scroll. +The native button's full-title tooltip says Switch to <title>. + +The existing resize target now paints a neutral grip with a visible keyboard +focus outline and Drag to resize inactive chat tooltip. Arrow keys and semantic +increase/decrease retain the saved bounds: nonzero minimum, maximum original20%. +Only the active bottom edge remains colored on the phone; no side edges added. + +Header and body stay stable siblings across role changes, preserving chat State, +drafts and reading offsets. The regular header reserves44px; compact native text +roles fit physically tiny previews, and the header is capped by actual available +height. Minimum48px peeks and32px visual previews are tested at2x text on Material +and Cupertino. Non-tape fixed-layout transitions hide the peek label until they +settle, preserving the source viewport and avoiding repeated expensive relayout. +Tape remains the default and its looping picture/joins are unchanged. + +51 workspace and Settings-preview tests passed (/tmp/memwatch/out.s8tNnF), including +all animation styles, draft/scroll retention, real remaining body viewport, +scroll-to-last-row, visible Switch activation once, min bounds and2x tiny sizes. +Analyzer clean (flutter-analyze.qg9nO5). Browser evidence is left to the parent's +integrated capture, where the body viewport must be compared with peek height +minus the visible header, not total peek-card height. No deployment performed. diff --git a/app/test/features/chat/workspace/chat_mobile_panes_test.dart b/app/test/features/chat/workspace/chat_mobile_panes_test.dart index 20596a37..22cb3c58 100644 --- a/app/test/features/chat/workspace/chat_mobile_panes_test.dart +++ b/app/test/features/chat/workspace/chat_mobile_panes_test.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/features/chat/workspace/chat_peek_header.dart'; import 'package:pipelines_app/features/chat/conversation/chat_pane_presentation.dart'; import 'package:pipelines_app/features/chat/workspace/chat_pane_backdrop.dart'; import 'package:pipelines_app/features/chat/workspace/chat_pane_switch_motion.dart'; @@ -165,7 +166,11 @@ void main() { expect(wrapped.top, greaterThan(_peekTop)); expect( tester.getSize(find.byKey(const ValueKey('b'))).height, - closeTo((800 - 6) * .2, .5), + closeTo( + (800 - 6) * .2 - + tester.getSize(find.byType(ChatPeekHeader).first).height, + .5, + ), ); expect( tester.getSize(find.byKey(const ValueKey('a'))).height, @@ -371,7 +376,11 @@ void main() { final peek = tester.getRect(rect(a)); expect( scrolls['a']!.position.viewportDimension, - closeTo(peek.height, .5), + closeTo( + peek.height - + tester.getSize(find.byType(ChatPeekHeader).first).height, + .5, + ), ); expect(find.byKey(const ValueKey('bar-a')), findsNothing); await tester.dragFrom(peek.center, const Offset(0, -90)); @@ -394,7 +403,11 @@ void main() { expect(scrolls['a']!.offset, 300); expect( scrolls['a']!.position.viewportDimension, - closeTo(peek.height, .5), + closeTo( + peek.height - + tester.getSize(find.byType(ChatPeekHeader).first).height, + .5, + ), ); expect(pressed, 0); await tester.pumpWidget(const SizedBox()); diff --git a/app/test/features/chat/workspace/chat_peek_identity_test.dart b/app/test/features/chat/workspace/chat_peek_identity_test.dart new file mode 100644 index 00000000..ba0917f3 --- /dev/null +++ b/app/test/features/chat/workspace/chat_peek_identity_test.dart @@ -0,0 +1,159 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/features/chat/workspace/chat_mobile_panes.dart'; +import 'package:pipelines_app/features/chat/workspace/chat_mobile_peek_divider.dart'; +import 'package:pipelines_app/features/chat/workspace/chat_peek_header.dart'; +import 'package:pipelines_app/features/chat/workspace/chat_workspace.dart'; + +class _Thread extends StatefulWidget { + const _Thread({super.key}); + @override + State<_Thread> createState() => _ThreadState(); +} + +class _ThreadState extends State<_Thread> { + final scroll = ScrollController(); + final draft = TextEditingController(text: 'Keep this draft'); + @override + void dispose() { + scroll.dispose(); + draft.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) => Material( + child: ListView( + controller: scroll, + children: [ + TextField(controller: draft), + for (var i = 0; i < 40; i++) + SizedBox(height: 48, child: Text('Line $i')), + ], + ), + ); +} + +void main() { + for (final cupertino in [false, true]) { + for (final height in [32.0, 48.0]) { + testWidgets( + 'peek title and switch fit $height height at 2x ($cupertino)', + (tester) async { + var activated = 0; + Size? bodySize; + final viewport = MediaQuery( + data: const MediaQueryData(textScaler: TextScaler.linear(2)), + child: Align( + alignment: Alignment.topLeft, + child: SizedBox( + width: 320, + height: height, + child: ChatMobilePaneViewport( + peek: true, + active: false, + barReveal: const AlwaysStoppedAnimation(0), + onActivate: () => activated++, + label: 'A long working project name', + paneId: 'first', + child: LayoutBuilder( + builder: (context, constraints) { + bodySize = constraints.biggest; + return const SizedBox.expand(); + }, + ), + ), + ), + ), + ); + await tester.pumpWidget( + cupertino + ? CupertinoApp(home: CupertinoPageScaffold(child: viewport)) + : MaterialApp(home: Scaffold(body: viewport)), + ); + expect(find.text('A long working project name'), findsOneWidget); + expect(find.text('Switch'), findsOneWidget); + final headerSize = tester.getSize(find.byType(ChatPeekHeader)); + expect(headerSize.height, lessThanOrEqualTo(height)); + expect(bodySize!.height, closeTo(height - headerSize.height, .01)); + await tester.tap(find.text('Switch')); + await tester.pump(); + expect(activated, 1); + expect(tester.takeException(), isNull); + }, + ); + } + } + testWidgets('peek header reserves real body space and keeps reading state', ( + tester, + ) async { + tester.view.physicalSize = const Size(560, 800); + tester.view.devicePixelRatio = 1; + addTearDown(tester.view.reset); + final panes = ChatWorkspaceController()..open('Project alpha'); + final first = panes.activePaneId!; + panes.splitActive('Project beta', ChatSplitAxis.horizontal); + final second = panes.activePaneId!; + await tester.pumpWidget( + MaterialApp( + home: MediaQuery( + data: const MediaQueryData(disableAnimations: true), + child: ChatWorkspace( + controller: panes, + singlePane: true, + mobilePeeks: true, + paneTitle: (pane) => pane.sessionId, + paneBuilder: (_, pane, active) => + _Thread(key: ValueKey(pane.sessionId)), + ), + ), + ), + ); + await tester.pumpAndSettle(); + final state = tester.state<_ThreadState>( + find.byKey(const ValueKey('Project alpha')), + ); + final peek = tester.getRect(find.byKey(ValueKey('chat-workspace-$first'))); + final header = tester.getRect(find.byType(ChatPeekHeader)); + expect(header.top, peek.top); + expect( + state.scroll.position.viewportDimension, + closeTo(peek.height - header.height, .01), + ); + state.scroll.jumpTo(state.scroll.position.maxScrollExtent); + await tester.pump(); + expect( + tester.getRect(find.text('Line 39').first).bottom, + closeTo(peek.bottom, .5), + ); + state.scroll.jumpTo(300); + await tester.pump(); + await tester.tap(find.text('Switch')); + await tester.pumpAndSettle(); + expect(panes.activePaneId, first); + expect( + tester.state(find.byKey(const ValueKey('Project alpha'))), + same(state), + ); + expect(state.draft.text, 'Keep this draft'); + expect(state.scroll.offset, 300); + panes.activate(second); + await tester.pumpAndSettle(); + expect(state.scroll.offset, 300); + expect(find.byTooltip('Drag to resize inactive chat'), findsOneWidget); + await tester.drag(find.byType(ChatMobilePeekDivider), const Offset(0, 500)); + await tester.pumpAndSettle(); + expect( + tester.getSize(find.byKey(ValueKey('chat-workspace-$first'))).height, + 48, + ); + expect( + state.scroll.position.viewportDimension, + closeTo(48 - header.height, .01), + ); + expect(tester.takeException(), isNull); + await tester.pumpWidget(const SizedBox()); + panes.dispose(); + }); +} diff --git a/app/test/features/chat/workspace/chat_switch_styles_test.dart b/app/test/features/chat/workspace/chat_switch_styles_test.dart index f1231499..c9d579ed 100644 --- a/app/test/features/chat/workspace/chat_switch_styles_test.dart +++ b/app/test/features/chat/workspace/chat_switch_styles_test.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/features/chat/workspace/chat_peek_header.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:pipelines_app/ui/motion/quick_switch_animation.dart'; import 'package:pipelines_app/features/chat/workspace/chat_workspace.dart'; @@ -142,7 +143,11 @@ void main() { expect(tester.getRect(rect(b)).top, _peekTop); expect( tester.getSize(find.byKey(const ValueKey('b'))).height, - closeTo((800 - 6) * .2, .01), + closeTo( + (800 - 6) * .2 - + tester.getSize(find.byType(ChatPeekHeader).first).height, + .01, + ), ); expect(find.byKey(const ValueKey('chat-swap-exit')), findsNothing); await tester.pumpWidget(const SizedBox());