From 292ed92dc3956a7fa11c3585edb462f16ae8f450 Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Sat, 7 Nov 2026 22:09:30 +0000 Subject: [PATCH] Add mobile chat opening identity transition --- .../chat/conversation/chat_thread_header.dart | 13 +++ .../chat/conversation/chat_thread_view.dart | 13 +++ app/lib/ui/adaptive/segmented_bar.dart | 3 + app/lib/ui/adaptive/segmented_bar_pieces.dart | 3 + app/notes/chat-open-transition.md | 5 + .../chat/chat_open_transition_test.dart | 106 ++++++++++++++++++ 6 files changed, 143 insertions(+) create mode 100644 app/notes/chat-open-transition.md create mode 100644 app/test/features/chat/chat_open_transition_test.dart diff --git a/app/lib/features/chat/conversation/chat_thread_header.dart b/app/lib/features/chat/conversation/chat_thread_header.dart index b9270b74..be6739aa 100644 --- a/app/lib/features/chat/conversation/chat_thread_header.dart +++ b/app/lib/features/chat/conversation/chat_thread_header.dart @@ -26,6 +26,8 @@ class ChatThreadHeader extends StatelessWidget { this.actions = const [], this.moreActions = const [], this.backdrop, + this.identity, + this.identityHeroTag, }); final String title; @@ -46,6 +48,10 @@ class ChatThreadHeader extends StatelessWidget { /// Painted over the bar's scrim, under its pieces (the chat's colour). final Widget? backdrop; + /// The chat identity carried from the mobile session row into this header. + final Widget? identity; + final String? identityHeroTag; + @override Widget build(BuildContext context) { final cupertino = @@ -54,6 +60,12 @@ class ChatThreadHeader extends StatelessWidget { builder: (context, constraints) { final textScale = MediaQuery.textScalerOf(context).scale(14) / 14; final compact = constraints.maxWidth / textScale < 800; + final heroIdentity = + identity == null || + identityHeroTag == null || + (MediaQuery.maybeDisableAnimationsOf(context) ?? false) + ? identity + : Hero(tag: identityHeroTag!, child: identity!); final bar = SegmentedBar( cupertino: cupertino, automaticallyImplyLeading: false, @@ -67,6 +79,7 @@ class ChatThreadHeader extends StatelessWidget { ) : null, title: title.isEmpty ? 'Chat' : title, + titleLeading: heroIdentity, subtitle: folder, subtitleIcon: cupertino ? CupertinoIcons.folder diff --git a/app/lib/features/chat/conversation/chat_thread_view.dart b/app/lib/features/chat/conversation/chat_thread_view.dart index 4ffcb673..bf1740e6 100644 --- a/app/lib/features/chat/conversation/chat_thread_view.dart +++ b/app/lib/features/chat/conversation/chat_thread_view.dart @@ -7,6 +7,7 @@ import 'package:flutter/rendering.dart'; import '../../../core/api_gateway.dart'; import '../../../core/servers/server_scope.dart'; import '../../../shell/shell_bar.dart'; +import '../../../shell/list_detail_policy.dart'; import '../data/chat_attachment_images.dart'; import '../data/chat_repository.dart'; import '../domain/chat_activity_detail.dart'; @@ -17,6 +18,7 @@ import '../domain/chat_transcript.dart'; import '../ui/sessions/chat_adaptive.dart'; import '../ui/sessions/chat_color_picker.dart'; import '../ui/sessions/session_actions.dart'; +import '../ui/sessions/session_row_content.dart'; import '../ui/transcript/chat_markdown_view.dart'; import '../ui/transcript/chat_message_view.dart'; import '../ui/transcript/chat_transcript_selection.dart'; @@ -1319,6 +1321,17 @@ class _ChatThreadViewState extends State { backdrop: ChatColorWash.bar(session: session), title: widget.title.trim(), folder: folder, + identity: + session == null || + MediaQuery.sizeOf(context).width >= kListDetailMinWidth + ? null + : ChatSessionAvatar(session: session, selected: true), + identityHeroTag: + session != null && + MediaQuery.sizeOf(context).width < kListDetailMinWidth && + !(MediaQuery.maybeDisableAnimationsOf(context) ?? false) + ? 'chat-identity-${widget.sessionId}' + : null, onInfo: _openInfo, showBack: canGoBack, // A pushed page keeps the platform's stock Back (pop this route); a diff --git a/app/lib/ui/adaptive/segmented_bar.dart b/app/lib/ui/adaptive/segmented_bar.dart index 37002cdd..31b80ac1 100644 --- a/app/lib/ui/adaptive/segmented_bar.dart +++ b/app/lib/ui/adaptive/segmented_bar.dart @@ -60,6 +60,7 @@ class SegmentedBar extends StatefulWidget this.onTitlePressed, this.expandableTitle = false, this.titleAction, + this.titleLeading, this.titleSemanticLabel, this.titleKey, this.actions = const [], @@ -107,6 +108,7 @@ class SegmentedBar extends StatefulWidget /// An action shown inside the expanded title pill. final Widget? titleAction; + final Widget? titleLeading; final String? titleSemanticLabel; /// The key of the title's button (or its content when not pressable). @@ -404,6 +406,7 @@ class _SegmentedBarState extends State { buttonKey: expanded ? null : titleKey, expanded: expanded, titleAction: expanded ? widget.titleAction : null, + leading: widget.titleLeading, foreground: foregroundColor, fill: pillColor, ); diff --git a/app/lib/ui/adaptive/segmented_bar_pieces.dart b/app/lib/ui/adaptive/segmented_bar_pieces.dart index 6f597b17..6d14b8b6 100644 --- a/app/lib/ui/adaptive/segmented_bar_pieces.dart +++ b/app/lib/ui/adaptive/segmented_bar_pieces.dart @@ -172,6 +172,7 @@ class SegmentedTitlePill extends StatelessWidget { this.buttonKey, this.expanded = false, this.titleAction, + this.leading, this.foreground, this.fill, }); @@ -187,6 +188,7 @@ class SegmentedTitlePill extends StatelessWidget { final Key? buttonKey; final bool expanded; final Widget? titleAction; + final Widget? leading; final Color? foreground; final Color? fill; @@ -207,6 +209,7 @@ class SegmentedTitlePill extends StatelessWidget { mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.center, children: [ + if (leading != null) ...[leading!, const SizedBox(width: 8)], Flexible( child: Column( mainAxisSize: MainAxisSize.min, diff --git a/app/notes/chat-open-transition.md b/app/notes/chat-open-transition.md new file mode 100644 index 00000000..9c7b8411 --- /dev/null +++ b/app/notes/chat-open-transition.md @@ -0,0 +1,5 @@ +# Mobile chat opening transition + +The mobile chat row and conversation header share the chat identity avatar through a native Flutter `Hero`. The identity is added inside the existing title pill, preserving the colored header wash and desktop title geometry. Wide list/detail panes and reduced-motion contexts do not create a flight. + +Focused behavioral coverage is in `test/features/chat/chat_open_transition_test.dart`; it uses a fake chat, checks the mobile route opens/returns with the identity in the header, verifies an intermediate Hero geometry during the route animation, and checks reduced motion omits `Hero`. diff --git a/app/test/features/chat/chat_open_transition_test.dart b/app/test/features/chat/chat_open_transition_test.dart new file mode 100644 index 00000000..6faa9879 --- /dev/null +++ b/app/test/features/chat/chat_open_transition_test.dart @@ -0,0 +1,106 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/features/chat/conversation/chat_thread_header.dart'; +import 'package:pipelines_app/features/chat/ui/sessions/session_row_content.dart'; +import 'package:pipelines_app/ui/theme/app_theme.dart'; + +const _session = { + 'id': 'fake-chat', + 'title': 'Fake chat', + 'directory': '/tmp/fake-chat', + 'color': 'blue', +}; + +void main() { + testWidgets('mobile identity flies into the header and returns to the row', ( + tester, + ) async { + tester.view.physicalSize = const Size(390, 844); + tester.view.devicePixelRatio = 1; + addTearDown(tester.view.reset); + await tester.pumpWidget( + MaterialApp( + theme: appLightTheme(), + builder: (context, child) => MediaQuery( + data: MediaQuery.of( + context, + ).copyWith(size: const Size(390, 844), disableAnimations: false), + child: child!, + ), + home: Scaffold( + body: ChatSessionRow( + session: _session, + onOpen: (session) => + Navigator.of( + tester.element(find.byType(ChatSessionRow)), + ).push( + MaterialPageRoute( + builder: (_) => Scaffold( + body: ChatThreadHeader( + title: 'Fake chat', + folder: 'fake-chat', + onInfo: () {}, + showBack: true, + identity: ChatSessionAvatar( + session: session, + selected: true, + ), + identityHeroTag: 'chat-identity-fake-chat', + ), + ), + ), + ), + onAction: (_) {}, + ), + ), + ), + ); + await tester.pump(); + expect(find.byType(Hero), findsOneWidget); + final rowAvatar = find.byType(ChatSessionAvatar); + final rowRect = tester.getRect(rowAvatar); + await tester.tap(find.byKey(const Key('chat-row-fake-chat'))); + await tester.pump(const Duration(milliseconds: 100)); + expect(find.text('Fake chat'), findsOneWidget); + final heroFinder = find.byType(Hero, skipOffstage: false); + final heroRects = [ + for (var index = 0; index < tester.widgetList(heroFinder).length; index++) + tester.getRect(heroFinder.at(index)), + ]; + expect(heroRects, hasLength(2)); + expect( + heroRects.any((rect) => rect.size != rowRect.size && rect != rowRect), + isTrue, + ); + await tester.pumpAndSettle(); + final headerAvatar = tester.getRect(find.byType(ChatSessionAvatar)); + expect(headerAvatar.top, isNot(rowRect.top)); + await tester.pageBack(); + await tester.pumpAndSettle(); + expect(find.byKey(const Key('chat-row-fake-chat')), findsOneWidget); + }); + + testWidgets('reduced motion keeps the identity in place without a Hero', ( + tester, + ) async { + await tester.pumpWidget( + MediaQuery( + data: const MediaQueryData(disableAnimations: true), + child: MaterialApp( + theme: appLightTheme(), + home: Scaffold( + body: ChatThreadHeader( + title: 'Fake chat', + folder: 'fake-chat', + onInfo: () {}, + identity: ChatSessionAvatar(session: _session, selected: true), + identityHeroTag: 'chat-identity-fake-chat', + ), + ), + ), + ), + ); + await tester.pump(); + expect(find.byType(Hero), findsNothing); + }); +}