Add mobile chat opening identity transition

This commit is contained in:
2026-11-07 22:09:30 +00:00
parent 63758cd176
commit 292ed92dc3
6 changed files with 143 additions and 0 deletions
@@ -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
@@ -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<ChatThreadView> {
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
+3
View File
@@ -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<SegmentedBar> {
buttonKey: expanded ? null : titleKey,
expanded: expanded,
titleAction: expanded ? widget.titleAction : null,
leading: widget.titleLeading,
foreground: foregroundColor,
fill: pillColor,
);
@@ -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,
+5
View File
@@ -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`.
@@ -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 = <String, dynamic>{
'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<void>(
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);
});
}