From b71345fe4e9dbe9ae91c57370eea0ac804525950 Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Wed, 4 Nov 2026 21:58:11 +0000 Subject: [PATCH] Chat composer pops in with the bar when a chat opens --- .../chat/conversation/chat_composer_bar.dart | 94 +++++---- app/notes/chat-composer-pop.md | 21 ++ .../chat/chat_composer_entrance_test.dart | 189 ++++++++++++++++++ .../conversation/chat_stop_icon_test.dart | 3 + 4 files changed, 265 insertions(+), 42 deletions(-) create mode 100644 app/notes/chat-composer-pop.md create mode 100644 app/test/features/chat/chat_composer_entrance_test.dart diff --git a/app/lib/features/chat/conversation/chat_composer_bar.dart b/app/lib/features/chat/conversation/chat_composer_bar.dart index d227f6ea..e75bfe02 100644 --- a/app/lib/features/chat/conversation/chat_composer_bar.dart +++ b/app/lib/features/chat/conversation/chat_composer_bar.dart @@ -23,6 +23,7 @@ import 'chat_composer_controller.dart'; import '../ui/transcript/chat_attachment_frame.dart'; import '../../../ui/adaptive/glass_bar.dart'; import '../../../ui/adaptive/glass_pill.dart'; +import '../../../ui/adaptive/pop_entrance.dart'; import 'chat_reading_width.dart'; import 'composer_focus_request.dart'; import 'composer_focus_restore.dart'; @@ -730,51 +731,60 @@ class _ChatComposerBarState extends State { onSelected: _completeCommand, ), ), - _pill( - context, - cupertino, - Column( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - if (extras.isNotEmpty) - Padding( - padding: const EdgeInsetsDirectional.fromSTEB( - 12, - 8, - 12, - 0, - ), - child: Column( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.stretch, - children: extras, - ), - ), - Row( - crossAxisAlignment: CrossAxisAlignment.end, - children: [ - _attach(context, cupertino), - Expanded( - child: Focus( - canRequestFocus: false, - includeSemantics: false, - onKeyEvent: _onKey, - child: _field(cupertino), + // The pill pops in with the app's shared entrance, as + // the bar's pieces do, once per chat: this state is keyed + // by the chat, and a rebuild (typing, the keyboard, a + // sheet closing) never replays it. It only paints, so the + // field takes focus and keys at once while it plays. + PopEntrance( + key: const ValueKey('chat-composer-entrance'), + child: _pill( + context, + cupertino, + Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + if (extras.isNotEmpty) + Padding( + padding: const EdgeInsetsDirectional.fromSTEB( + 12, + 8, + 12, + 0, + ), + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: + CrossAxisAlignment.stretch, + children: extras, ), ), - // Shown only while tasks run (or their list - // cannot be read); a quiet control, not a - // caption. - ?widget.backgroundTasks, - if (widget.running) ...[ - _primary(context, cupertino, stop: true), - const SizedBox(width: 4), + Row( + crossAxisAlignment: CrossAxisAlignment.end, + children: [ + _attach(context, cupertino), + Expanded( + child: Focus( + canRequestFocus: false, + includeSemantics: false, + onKeyEvent: _onKey, + child: _field(cupertino), + ), + ), + // Shown only while tasks run (or their list + // cannot be read); a quiet control, not a + // caption. + ?widget.backgroundTasks, + if (widget.running) ...[ + _primary(context, cupertino, stop: true), + const SizedBox(width: 4), + ], + _primary(context, cupertino), ], - _primary(context, cupertino), - ], - ), - ], + ), + ], + ), ), ), ], diff --git a/app/notes/chat-composer-pop.md b/app/notes/chat-composer-pop.md new file mode 100644 index 00000000..1e836606 --- /dev/null +++ b/app/notes/chat-composer-pop.md @@ -0,0 +1,21 @@ +# Chat composer pops in with the bar + +- The composer's glass pill (`chat_composer_bar.dart`) is wrapped in the shared + `PopEntrance` (`lib/ui/adaptive/pop_entrance.dart`), glass mode, no delay: it + pops with the bar's pieces using the same `Motion.tabEntrance*` pop, its blur + fading through `GlassReveal`. No new animation or constants. +- Once per chat appearance: `ChatComposerBar` is keyed by the session + (`chat-composer-`), so opening or switching a chat (a tap, Ctrl+1-9) + builds a new entrance; typing, the keyboard, sheets and other rebuilds keep + the decided one. Reduced motion (`MediaQuery.disableAnimations`): it appears. +- It only paints (transform + fade), so the field keeps its layout and takes + focus and typing while it plays; the transcript does not move. +- Tests: `test/features/chat/chat_composer_entrance_test.dart` (opts back into + platform animations, which `flutter_test_config.dart` disables for chat tests). +- Evidence (probe app, Material dark): `/tmp/a646-cap/desktop/open` + (1280x800 open), `/tmp/a646-cap/switch/switch` (chat 1 -> 2), + `/tmp/a646-cap/phone/open` (560x1000); `strip-*.png` in `/tmp/a646-cap` + stack the bar and composer bands of every frame. Title and composer fade in + small together, overshoot slightly and settle. +- There is no "Next chat" command on this branch; any future one goes through + the same keyed composer. diff --git a/app/test/features/chat/chat_composer_entrance_test.dart b/app/test/features/chat/chat_composer_entrance_test.dart new file mode 100644 index 00000000..24febb66 --- /dev/null +++ b/app/test/features/chat/chat_composer_entrance_test.dart @@ -0,0 +1,189 @@ +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/core/api_gateway.dart'; +import 'package:pipelines_app/features/chat/screen.dart'; +import 'package:pipelines_app/shell/adaptive_shell.dart'; +import 'package:pipelines_app/shell/destination.dart'; +import 'package:pipelines_app/ui/adaptive/pop_entrance.dart'; +import 'package:pipelines_app/ui/adaptive/segmented_bar.dart'; +import 'package:shared_preferences/shared_preferences.dart'; + +import 'conversation/chat_thread_fixtures.dart'; + +class _Gateway extends FakeChatGateway { + @override + Future call(String type, [JsonMap fields = const {}]) { + if (type == 'chat_sessions') { + return Future.value({ + 'chat_sessions': [ + {'id': 'r', 'title': 'Recent', 'directory': '/w'}, + {'id': 'z', 'title': 'Zed', 'directory': '/w'}, + ], + }); + } + if (type == 'chat_shells') return Future.value({'chat_shells': []}); + return super.call(type, fields); + } +} + +Future _pumpShell( + WidgetTester tester, + Size size, { + bool reduced = false, +}) async { + SharedPreferences.setMockInitialValues({}); + // The chat tests run with the platform's reduced motion (see + // flutter_test_config.dart); these opt back in, so controllers keep their + // real durations, and choose reduced motion through the app's MediaQuery. + tester.platformDispatcher.accessibilityFeaturesTestValue = + const FakeAccessibilityFeatures(); + addTearDown( + () => tester.platformDispatcher.accessibilityFeaturesTestValue = + const FakeAccessibilityFeatures(disableAnimations: true), + ); + tester.view.physicalSize = size; + tester.view.devicePixelRatio = 1; + addTearDown(tester.view.reset); + final gateway = _Gateway()..history = (_) async => chatPage(const []); + addTearDown(gateway.close); + await tester.pumpWidget( + MaterialApp( + theme: ThemeData(platform: TargetPlatform.android), + builder: (context, child) => MediaQuery( + data: MediaQuery.of(context).copyWith(disableAnimations: reduced), + child: child!, + ), + home: AdaptiveShell( + cupertino: false, + destination: AppDestination.chat, + destinationBodies: { + AppDestination.chat: (_) => ChatScreen(gateway: gateway), + }, + ), + ), + ); + await tester.pumpAndSettle(); +} + +Finder _composer(String id) => find.byKey(ValueKey('chat-composer-$id')); + +/// The composer pill's entrance. +PopAnimations _pop(WidgetTester tester, String id) => tester + .widget( + find.descendant(of: _composer(id), matching: find.byType(PopTransition)), + ) + .animations; + +bool _playing(PopAnimations pop) => pop.opacity.value < 1; + +EditableText _field(WidgetTester tester, String id) => + tester.widget( + find.descendant(of: _composer(id), matching: find.byType(EditableText)), + ); + +Future _ctrl(WidgetTester tester, LogicalKeyboardKey digit) async { + await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft); + await tester.sendKeyEvent(digit); + await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft); +} + +/// Whether any piece of the top bar is still popping in. +bool _barPlaying(WidgetTester tester) => tester + .widgetList( + find.descendant( + of: find.byType(SegmentedBar), + matching: find.byType(PopTransition), + ), + ) + .any((transition) => _playing(transition.animations)); + +void main() { + testWidgets('the composer pops in with the bar when a chat opens and ' + 'again when another chat opens', (tester) async { + await _pumpShell(tester, const Size(1280, 800)); + await tester.tap(find.byKey(const Key('chat-row-r'))); + await tester.pump(); + await tester.pump(const Duration(milliseconds: 16)); + expect(_playing(_pop(tester, 'r')), isTrue); + expect(_barPlaying(tester), isTrue); + await tester.pumpAndSettle(); + expect(_pop(tester, 'r').opacity.value, 1); + + await tester.tap(find.byKey(const Key('chat-row-z'))); + await tester.pump(); + await tester.pump(const Duration(milliseconds: 16)); + expect(_playing(_pop(tester, 'z')), isTrue); + await tester.pumpAndSettle(); + expect(_pop(tester, 'z').opacity.value, 1); + await tester.pumpWidget(const SizedBox.shrink()); + }); + + testWidgets('typing, the keyboard and a sheet never replay it', ( + tester, + ) async { + await _pumpShell(tester, const Size(390, 844)); + await tester.tap(find.byKey(const Key('chat-row-r'))); + await tester.pumpAndSettle(); + final settled = _pop(tester, 'r'); + expect(settled.opacity.value, 1); + + await tester.enterText( + find.descendant(of: _composer('r'), matching: find.byType(EditableText)), + 'hello', + ); + await tester.pump(); + expect(_playing(_pop(tester, 'r')), isFalse); + + // The on-screen keyboard rises and falls. + tester.view.viewInsets = const FakeViewPadding(bottom: 320); + await tester.pump(); + expect(_playing(_pop(tester, 'r')), isFalse); + tester.view.resetViewInsets(); + await tester.pump(); + expect(_playing(_pop(tester, 'r')), isFalse); + + // A sheet over the chat opens and closes. + showModalBottomSheet( + context: tester.element(_composer('r')), + builder: (_) => const SizedBox(height: 200, child: Text('sheet')), + ); + await tester.pumpAndSettle(); + Navigator.of(tester.element(find.text('sheet'))).pop(); + await tester.pump(); + expect(_playing(_pop(tester, 'r')), isFalse); + await tester.pumpAndSettle(); + expect(identical(_pop(tester, 'r').pop, settled.pop), isTrue); + await tester.pumpWidget(const SizedBox.shrink()); + }); + + testWidgets('under reduced motion the composer simply appears', ( + tester, + ) async { + await _pumpShell(tester, const Size(1280, 800), reduced: true); + await tester.tap(find.byKey(const Key('chat-row-r'))); + await tester.pump(); + expect(_pop(tester, 'r'), same(poppedIn)); + await tester.pumpWidget(const SizedBox.shrink()); + }); + + for (final size in [const Size(1280, 800), const Size(390, 844)]) { + testWidgets('Ctrl+N focuses the composer while it is still popping in ' + '(${size.width.toInt()} wide)', (tester) async { + await _pumpShell(tester, size); + await _ctrl(tester, LogicalKeyboardKey.digit2); + // The switch frame, then the frame after it that takes the focus. + await tester.pump(); + await tester.pump(const Duration(milliseconds: 16)); + await tester.pump(const Duration(milliseconds: 16)); + expect(_playing(_pop(tester, 'z')), isTrue); + expect(_field(tester, 'z').focusNode.hasPrimaryFocus, isTrue); + tester.testTextInput.enterText('h'); + await tester.pump(); + expect(_field(tester, 'z').controller.text, 'h'); + await tester.pumpAndSettle(); + expect(_field(tester, 'z').focusNode.hasPrimaryFocus, isTrue); + await tester.pumpWidget(const SizedBox.shrink()); + }); + } +} diff --git a/app/test/features/chat/conversation/chat_stop_icon_test.dart b/app/test/features/chat/conversation/chat_stop_icon_test.dart index e89e50ae..bddcf1f6 100644 --- a/app/test/features/chat/conversation/chat_stop_icon_test.dart +++ b/app/test/features/chat/conversation/chat_stop_icon_test.dart @@ -5,6 +5,7 @@ import 'package:pipelines_app/features/chat/conversation/chat_stop_icon.dart'; import 'package:pipelines_app/features/chat/conversation/chat_composer_bar.dart'; import 'package:pipelines_app/features/chat/conversation/chat_composer_controller.dart'; import 'package:pipelines_app/features/chat/conversation/chat_draft_store.dart'; +import 'package:pipelines_app/ui/motion/motion.dart'; import 'chat_composer_bar_fixtures.dart'; @@ -148,6 +149,8 @@ void main() { home: Scaffold(body: Center(child: bar)), ), ); + // The composer pops in first; Stop's target is measured once it has. + await tester.pump(Motion.tabEntranceDuration); final stop = find.byKey(const Key('chat-composer-stop')); final target = tester.getRect(stop); await tester.pump(const Duration(seconds: 3));