diff --git a/app/lib/features/chat/conversation/chat_thread_view.dart b/app/lib/features/chat/conversation/chat_thread_view.dart index 87e7eae2..0836adfe 100644 --- a/app/lib/features/chat/conversation/chat_thread_view.dart +++ b/app/lib/features/chat/conversation/chat_thread_view.dart @@ -1334,7 +1334,8 @@ class _ChatThreadViewState extends State { ? null : ChatSessionAvatar(session: session, selected: true), identityHeroTag: - session != null && + widget.useNativeBack && + session != null && MediaQuery.sizeOf(context).width < kListDetailMinWidth && !(MediaQuery.maybeDisableAnimationsOf(context) ?? false) ? 'chat-identity-${widget.sessionId}' diff --git a/app/lib/features/chat/screen.dart b/app/lib/features/chat/screen.dart index f3a67bb1..f4eb0760 100644 --- a/app/lib/features/chat/screen.dart +++ b/app/lib/features/chat/screen.dart @@ -24,6 +24,7 @@ import 'conversation/chat_add_pane_picker.dart'; import 'conversation/chat_sidebar_controls.dart'; import 'ui/sessions/chat_compact_sidebar.dart'; import 'workspace/chat_workspace.dart'; +import 'workspace/chat_workspace_entrance.dart'; import 'ui/sessions/chat_adaptive.dart'; import 'conversation/chat_row_widgets.dart'; import 'conversation/chat_scroll.dart'; @@ -572,8 +573,10 @@ class _ChatScreenState extends State offstage: selected != null, child: ExcludeFocus(excluding: selected != null, child: list), ), - Offstage( - offstage: selected == null, + ChatWorkspaceEntrance( + visible: selected != null, + cupertino: + chatControlsStyleOf(context) == ChatControlsStyle.cupertino, child: ExcludeFocus( excluding: selected == null, child: MediaQuery( diff --git a/app/lib/features/chat/workspace/chat_workspace_entrance.dart b/app/lib/features/chat/workspace/chat_workspace_entrance.dart new file mode 100644 index 00000000..3bec11a9 --- /dev/null +++ b/app/lib/features/chat/workspace/chat_workspace_entrance.dart @@ -0,0 +1,102 @@ +import 'package:flutter/cupertino.dart'; + +import '../../../ui/motion/motion.dart'; + +/// Reopens a retained mobile workspace without moving it to another route. +/// Its child keeps the same element, scroll positions, panes and drafts. +class ChatWorkspaceEntrance extends StatefulWidget { + const ChatWorkspaceEntrance({ + super.key, + required this.visible, + required this.cupertino, + required this.child, + }); + + final bool visible; + final bool cupertino; + final Widget child; + + @override + State createState() => _ChatWorkspaceEntranceState(); +} + +class _ChatWorkspaceEntranceState extends State + with SingleTickerProviderStateMixin { + late final _controller = AnimationController( + vsync: this, + value: widget.visible ? 1 : 0, + ); + late final _curve = CurvedAnimation( + parent: _controller, + curve: Motion.curve, + reverseCurve: Curves.easeInCubic, + ); + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + _controller.duration = Motion.of(context, Motion.tabEntranceDuration); + if (_controller.duration == Duration.zero) { + _controller.value = widget.visible ? 1 : 0; + } + } + + @override + void didUpdateWidget(ChatWorkspaceEntrance oldWidget) { + super.didUpdateWidget(oldWidget); + if (oldWidget.visible != widget.visible) { + if (_controller.duration == Duration.zero) { + _controller.value = widget.visible ? 1 : 0; + } else if (widget.visible) { + _controller.forward(); + } else { + _controller.reverse(); + } + } + } + + @override + void dispose() { + _curve.dispose(); + _controller.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + final content = HeroMode( + // The initial pushed page has a native Hero. Here both surfaces share + // one route; only the workspace entrance animates, never duplicate tags. + enabled: false, + child: TickerMode(enabled: widget.visible, child: widget.child), + ); + final transition = widget.cupertino + ? CupertinoPageTransition( + primaryRouteAnimation: _controller, + secondaryRouteAnimation: const AlwaysStoppedAnimation(0), + linearTransition: false, + child: content, + ) + : FadeTransition( + opacity: _curve, + child: SlideTransition( + position: Tween( + begin: const Offset(0, 0.08), + end: Offset.zero, + ).animate(_curve), + child: content, + ), + ); + return AnimatedBuilder( + animation: _controller, + child: transition, + builder: (context, child) => Offstage( + offstage: !widget.visible && _controller.isDismissed, + child: IgnorePointer( + ignoring: !widget.visible, + child: ExcludeSemantics(excluding: !widget.visible, child: child!), + ), + ), + ); + } +} diff --git a/app/notes/retained-chat-entrance.md b/app/notes/retained-chat-entrance.md new file mode 100644 index 00000000..788837b0 --- /dev/null +++ b/app/notes/retained-chat-entrance.md @@ -0,0 +1,36 @@ +# Retained mobile chat entrance + +A restored workspace reopens inside the retained Chat destination rather than +pushing a new route. Heroes cannot fly between two children of that same route. +It now enters with a short Material fade/up motion or the native +`CupertinoPageTransition`. The existing initial pushed chat page retains its +shared-avatar Hero. Its header Hero is scoped to that native-page path, avoiding +duplicate tags when the retained list and body coexist during fold/unfold. + +`ChatWorkspaceEntrance` keeps its child mounted at full layout size, then changes +only paint translation/opacity. It never moves the GlobalKey workspace between +routes or replaces its panes. Hidden children disable tickers and interaction; +exit semantics are hidden immediately. Reduced motion is instant; the existing +global scheduler speed clock applies once to the 260ms base duration. + +Checks: +- Six focused tests passed (`/tmp/memwatch/out.1OnK0u`): real full-app restored + multi-pane Back → Runs → Chat → Chat-retap, same workspace and active thread + State instances, pane order/active id/peek ratio/drafts/scroll retained, and an + intermediate entrance position. Both host entrance tests retain the same + text field State/draft and check reduced motion. +- 37 more passed (`/tmp/memwatch/out.GBlouj`), including all 24 phone/wide + list-detail consistency cases, initial shared-avatar Hero, saved workspace + restoration and mobile quick switch. No duplicate Hero errors. +- Analyzer clean (`flutter-analyze.8tHmKg`). +- Full-app fake-gateway browser film at 560x1000, seeded private saved layout, + 80 rich messages and two panes: Back → list-row reopen, then Back → Chats-tab + retap both animate and retain the draft. Inspected before/after PNGs and both + contact sheets in `/tmp/retained-transition-final/`; final focused textarea + readback is `Retained pane draft`. Script: `/tmp/retained-transition-capture.json`. + +The browser capture uses mouse clicks at phone layout width. Touch emulation +in the generic capture kit could not re-enable semantics after a second page +navigation; that failed setup is not device evidence. No Android hardware test +or FPS claim. All owned capture/test/build processes completed. No deployment, +server restart or live operator data mutation. diff --git a/app/test/application/chat_registration_test.dart b/app/test/application/chat_registration_test.dart index 07d5992e..bd8b8b88 100644 --- a/app/test/application/chat_registration_test.dart +++ b/app/test/application/chat_registration_test.dart @@ -12,6 +12,7 @@ import 'package:pipelines_app/core/transport/pipelines_client.dart'; import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart'; import 'package:pipelines_app/features/chat/conversation/chat_composer_bar.dart'; import 'package:pipelines_app/features/chat/workspace/chat_workspace.dart'; +import 'package:pipelines_app/features/chat/workspace/chat_workspace_store.dart'; import 'package:pipelines_app/features/chat/workspace/chat_mobile_peek_divider.dart'; import 'package:pipelines_app/features/chat/ui/sessions/chat_sessions_screen.dart'; @@ -321,7 +322,21 @@ void main() { testWidgets( 'mobile Chats retap reopens the retained multi-pane workspace after tabs', (tester) async { - SharedPreferences.setMockInitialValues({}); + // A restored empty layout chooses the retained inline mobile path from + // the first selection, rather than the initial pushed detail route. + SharedPreferences.setMockInitialValues({ + chatWorkspacePreferenceKey: jsonEncode({ + 'version': 1, + 'root': null, + 'active_pane': null, + 'sidebar_mode': 'expanded', + }), + }); + tester.platformDispatcher.accessibilityFeaturesTestValue = + const FakeAccessibilityFeatures(disableAnimations: false); + addTearDown( + tester.platformDispatcher.clearAccessibilityFeaturesTestValue, + ); tester.view.physicalSize = const Size(560, 1000); tester.view.devicePixelRatio = 1; addTearDown(tester.view.reset); @@ -348,6 +363,9 @@ void main() { await tester.tap(find.text('Chat a').first); await tester.pump(); + expect(provider.value.uri.path, '/chat/a'); + expect(find.byType(ChatThreadView), findsOneWidget); + await replyChatSessions(tester, channel, ['a', 'b'], index: 1); await replyChatHistory( tester, channel, @@ -409,6 +427,11 @@ void main() { expect(workspace.controller.paneCount, 2); expect(workspace.controller.activePane?.sessionId, 'b'); expect(provider.value.uri.path, '/chat/b'); + final workspaceState = tester.state(find.byType(ChatWorkspace)); + final activeThreadState = tester.state( + find.byKey(const ValueKey('chat-session-b')), + ); + final restingTop = tester.getTopLeft(find.byType(ChatWorkspace)).dy; final paneOrder = workspace.controller.panes .map((p) => p.sessionId) .toList(); @@ -455,7 +478,20 @@ void main() { // The selected Chats destination is already showing its list: the // second tap reuses the mounted workspace instead of opening a new one. await tester.tap(find.byKey(const ValueKey('shell.destination.chat'))); + await tester.pump(); + final enteringTop = tester.getTopLeft(find.byType(ChatWorkspace)).dy; + expect(enteringTop, greaterThan(restingTop + 1)); + await tester.pump(const Duration(milliseconds: 80)); + final midwayTop = tester.getTopLeft(find.byType(ChatWorkspace)).dy; + expect(midwayTop, greaterThan(restingTop + 1)); + expect(midwayTop, lessThan(enteringTop)); await tester.pumpAndSettle(); + expect(tester.getTopLeft(find.byType(ChatWorkspace)).dy, restingTop); + expect(tester.state(find.byType(ChatWorkspace)), same(workspaceState)); + expect( + tester.state(find.byKey(const ValueKey('chat-session-b'))), + same(activeThreadState), + ); expect(provider.value.uri.path, '/chat/b'); final restored = tester.widget(find.byType(ChatWorkspace)); expect(restored.controller, same(workspace.controller)); diff --git a/app/test/features/chat/workspace/chat_workspace_entrance_test.dart b/app/test/features/chat/workspace/chat_workspace_entrance_test.dart new file mode 100644 index 00000000..8ae3a24e --- /dev/null +++ b/app/test/features/chat/workspace/chat_workspace_entrance_test.dart @@ -0,0 +1,58 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/features/chat/workspace/chat_workspace_entrance.dart'; + +void main() { + for (final cupertino in [false, true]) { + testWidgets('retained entrance moves the same child ($cupertino)', ( + tester, + ) async { + tester.platformDispatcher.accessibilityFeaturesTestValue = + const FakeAccessibilityFeatures(disableAnimations: false); + addTearDown( + tester.platformDispatcher.clearAccessibilityFeaturesTestValue, + ); + final childKey = GlobalKey(); + final child = TextField(key: childKey); + Widget host(bool visible, {bool reduced = false}) => MaterialApp( + home: MediaQuery( + data: MediaQueryData(disableAnimations: reduced), + child: SizedBox.expand( + child: ChatWorkspaceEntrance( + visible: visible, + cupertino: cupertino, + child: Material(child: child), + ), + ), + ), + ); + await tester.pumpWidget(host(false)); + final element = childKey.currentContext; + final state = childKey.currentState; + expect(find.byKey(childKey), findsNothing); + await tester.pumpWidget(host(true)); + final start = tester.getTopLeft(find.byKey(childKey)); + await tester.pump(); + await tester.pump(const Duration(milliseconds: 80)); + final middle = tester.getTopLeft(find.byKey(childKey)); + await tester.pumpAndSettle(); + final end = tester.getTopLeft(find.byKey(childKey)); + expect(cupertino ? middle.dx : middle.dy, greaterThan(0)); + expect( + cupertino ? middle.dx : middle.dy, + lessThan(cupertino ? start.dx : start.dy), + ); + expect(end, Offset.zero); + expect(childKey.currentContext, same(element)); + expect(childKey.currentState, same(state)); + await tester.enterText(find.byType(TextField), 'Retained draft'); + await tester.pumpWidget(host(false)); + await tester.pumpAndSettle(); + await tester.pumpWidget(host(true, reduced: true)); + expect(tester.getTopLeft(find.byKey(childKey)), Offset.zero); + expect(find.text('Retained draft'), findsOneWidget); + expect(childKey.currentState, same(state)); + expect(tester.takeException(), isNull); + }); + } +}