diff --git a/app/lib/features/chat/workspace/chat_pane_switch_motion.dart b/app/lib/features/chat/workspace/chat_pane_switch_motion.dart index 2bf9b5da..8ebee36d 100644 --- a/app/lib/features/chat/workspace/chat_pane_switch_motion.dart +++ b/app/lib/features/chat/workspace/chat_pane_switch_motion.dart @@ -1,9 +1,11 @@ +import 'dart:math' as math; import 'dart:ui' show lerpDouble; import 'package:flutter/foundation.dart'; import 'package:flutter/widgets.dart'; +import '../../../ui/motion/quick_switch_animation.dart'; -/// A looping vertical tape. The old active picture exits above the incoming -/// live chat, while its retained live view re-enters below at the peek height. +/// A vertical tape or a live card exchange, selected once for each transition. +/// Tape uses an outgoing picture; swaps move the retained chats themselves. /// Every live transcript exists once and keeps its real visible viewport. class ChatPaneSwitchMotion { ChatPaneSwitchMotion({required TickerProvider vsync}) @@ -27,6 +29,18 @@ class ChatPaneSwitchMotion { String? _outgoingId; String? _enteringPeekId; Rect? outgoingSourceRect; + QuickSwitchAnimation _style = QuickSwitchAnimation.tape; + QuickSwitchAnimation get style => _style; + bool get isTape => _style == QuickSwitchAnimation.tape; + double get progress => _progress; + bool get outgoingOnTop => !isTape && _progress < .5; + bool isRetainedOutgoing(String id) => + isAnimating && !isTape && id == _outgoingId; + String? get topPaneId => outgoingOnTop ? _outgoingId : _activeId; + double opacityFor(String id) => + isAnimating && !isTape && id == _enteringPeekId && id != _outgoingId + ? _progress + : 1; bool get isAnimating => _controller.isAnimating; double get _progress => curve.transform(_controller.value); @@ -41,6 +55,7 @@ class ChatPaneSwitchMotion { required String activeId, required bool switching, required bool animate, + QuickSwitchAnimation style = QuickSwitchAnimation.tape, }) { final travel = switching && @@ -51,13 +66,17 @@ class ChatPaneSwitchMotion { _activeId != activeId; _size = size; if (travel) { + _style = style; _outgoingId = _activeId; outgoingSourceRect = _to[_outgoingId]; _enteringPeekId = rects.keys.firstWhere((id) => id != activeId); final peek = rects[_enteringPeekId]!; _from = {..._to, activeId: _to[activeId] ?? peek}; _to = rects; - _barFrom = {for (final id in rects.keys) id: 0}; + _barFrom = { + for (final id in {...rects.keys, _outgoingId!}) + id: !isTape && id == _outgoingId ? 1 : 0, + }; _barTo = {for (final id in rects.keys) id: id == activeId ? 1 : 0}; _activeId = activeId; _controller.forward(from: 0); @@ -85,8 +104,9 @@ class ChatPaneSwitchMotion { Rect? rectFor(String id) { final to = _to[id]; + if (isRetainedOutgoing(id)) return exitingRect; if (to == null) return null; - if (_enteringPeekId == id && outgoingSourceRect != null) { + if (isTape && _enteringPeekId == id && outgoingSourceRect != null) { // The next pane in the ring enters from below with a true small // viewport. With two panes this is the outgoing chat; with more it is // the next added pane. The old active owns only the snapshot top exit. @@ -100,7 +120,15 @@ class ChatPaneSwitchMotion { final source = outgoingSourceRect; final incoming = _from[_activeId]; if (!isAnimating || source == null || incoming == null) return null; - return source.translate(0, -incoming.top * _progress); + if (isTape) return source.translate(0, -incoming.top * _progress); + final target = _to[_enteringPeekId] ?? source; + final rect = Rect.lerp(source, target, _progress)!; + if (_style == QuickSwitchAnimation.swap) return rect; + final lift = math.sin(math.pi * _progress); + return rect.translate( + -source.width * .18 * lift, + -source.height * .08 * lift, + ); } void dispose() => _controller.dispose(); diff --git a/app/lib/features/chat/workspace/chat_switch_card.dart b/app/lib/features/chat/workspace/chat_switch_card.dart new file mode 100644 index 00000000..2bde4072 --- /dev/null +++ b/app/lib/features/chat/workspace/chat_switch_card.dart @@ -0,0 +1,53 @@ +import 'dart:math' as math; +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import '../../../ui/adaptive/host.dart'; +import '../../../ui/motion/quick_switch_animation.dart'; +import 'chat_pane_switch_motion.dart'; + +/// Perspective affects paint only. The retained chat keeps its real viewport +/// and its scroll controllers, focus scope and draft throughout the exchange. +class ChatSwitchCard extends StatelessWidget { + const ChatSwitchCard({ + super.key, + required this.motion, + required this.outgoing, + required this.child, + }); + final ChatPaneSwitchMotion motion; + final bool outgoing; + final Widget child; + + @override + Widget build(BuildContext context) { + final lift = + motion.isAnimating && motion.style == QuickSwitchAnimation.cardStack + ? math.sin(math.pi * motion.progress) + : 0.0; + final direction = outgoing ? -1.0 : 1.0; + final transform = Matrix4.identity() + ..setEntry(3, 2, .0012 * lift) + ..translateByDouble(0, 0, -(outgoing ? 90 : 40) * lift, 1) + ..rotateY(direction * .22 * lift) + ..rotateZ(direction * .035 * lift); + final shadow = usesCupertinoHost(context) + ? CupertinoColors.black + : Theme.of(context).shadowColor; + return Transform( + alignment: Alignment.center, + transform: transform, + child: DecoratedBox( + decoration: BoxDecoration( + boxShadow: [ + BoxShadow( + color: shadow.withValues(alpha: .24 * lift), + blurRadius: 22 * lift, + offset: Offset(0, 8 * lift), + ), + ], + ), + child: child, + ), + ); + } +} diff --git a/app/lib/features/chat/workspace/chat_workspace.dart b/app/lib/features/chat/workspace/chat_workspace.dart index 9db9b68c..04750a27 100644 --- a/app/lib/features/chat/workspace/chat_workspace.dart +++ b/app/lib/features/chat/workspace/chat_workspace.dart @@ -3,6 +3,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; +import '../../../ui/motion/quick_switch_animation.dart'; import 'chat_workspace_controller.dart'; import 'chat_workspace_geometry.dart'; import 'chat_mobile_panes.dart'; @@ -84,9 +85,7 @@ class _ChatWorkspaceState extends State void _motionSettled(AnimationStatus status) { if (status != AnimationStatus.completed) return; WidgetsBinding.instance.addPostFrameCallback((_) { - if (mounted && widget.controller.activePaneId != _lastActiveId) { - setState(() {}); - } + if (mounted) setState(() {}); }); } @@ -150,7 +149,10 @@ class _ChatWorkspaceState extends State Widget build(BuildContext context) => Focus( focusNode: _focus, child: ListenableBuilder( - listenable: widget.controller, + listenable: Listenable.merge([ + widget.controller, + QuickSwitchAnimationController.instance, + ]), builder: (context, _) => LayoutBuilder( builder: (context, constraints) { final root = widget.controller.root; @@ -182,7 +184,11 @@ class _ChatWorkspaceState extends State ) : null; var animate = !MediaQuery.disableAnimationsOf(context); - if (mobile != null && switching && animate) { + if (mobile != null && + switching && + animate && + QuickSwitchAnimationController.instance.value == + QuickSwitchAnimation.tape) { // The top exit requires a fresh picture. If painting is not ready, // settle safely instead of moving the only live tree offscreen. animate = _backdrop.capture(context); @@ -196,6 +202,7 @@ class _ChatWorkspaceState extends State activeId: activeId!, switching: switching, animate: animate, + style: QuickSwitchAnimationController.instance.value, ); } _reportVisible({ @@ -234,11 +241,12 @@ class _ChatWorkspaceState extends State bool collapsed, String? activeId, ) { - final peek = mobile?.peekId == pane.id; + final outgoing = _motion.isRetainedOutgoing(pane.id); + final peek = mobile?.peekId == pane.id || outgoing; final active = pane.id == activeId; return Offstage( offstage: mobile != null - ? !mobile.rects.containsKey(pane.id) + ? !mobile.rects.containsKey(pane.id) && !outgoing : collapsed && !active, child: ExcludeFocus( excluding: collapsed && !active, diff --git a/app/lib/features/chat/workspace/chat_workspace_surface.dart b/app/lib/features/chat/workspace/chat_workspace_surface.dart index d30f1f95..33a50ea0 100644 --- a/app/lib/features/chat/workspace/chat_workspace_surface.dart +++ b/app/lib/features/chat/workspace/chat_workspace_surface.dart @@ -6,6 +6,7 @@ import 'chat_mobile_peek_divider.dart'; import 'chat_pane_backdrop.dart'; import 'chat_pane_switch_motion.dart'; import 'chat_tape_exit.dart'; +import 'chat_switch_card.dart'; import 'chat_workspace_controller.dart'; import 'chat_workspace_divider.dart'; import 'chat_workspace_geometry.dart'; @@ -25,31 +26,25 @@ Widget chatWorkspaceSurface({ required Widget Function(ChatWorkspacePane) paneView, }) { final ordered = mobile?.paintOrder(panes) ?? panes; - return ChatPanePicture( - key: backdrop.pictureKey, - child: Stack( - fit: StackFit.expand, - clipBehavior: Clip.hardEdge, - children: [ - if (mobile != null) - ColoredBox( - color: usesCupertinoHost(context) - ? CupertinoTheme.of(context).scaffoldBackgroundColor - : Theme.of(context).colorScheme.surface, - ), - if (backdrop.image != null && mobile != null) - AnimatedBuilder( - animation: motion.animation, - builder: (context, _) { - final rect = motion.exitingRect; - final source = motion.outgoingSourceRect; - if (rect == null || source == null) { - return const SizedBox.shrink(); - } - return Positioned.fromRect( - key: const ValueKey('chat-tape-exit'), - rect: rect, - child: IgnorePointer( + final picture = backdrop.image != null && mobile != null && motion.isTape + ? AnimatedBuilder( + key: const ValueKey('chat-switch-picture'), + animation: motion.animation, + builder: (context, _) { + final rect = motion.exitingRect; + final source = motion.outgoingSourceRect; + if (rect == null || source == null) { + return const SizedBox.shrink(); + } + return Positioned.fromRect( + key: ValueKey( + motion.isTape ? 'chat-tape-exit' : 'chat-swap-exit', + ), + rect: rect, + child: IgnorePointer( + child: ChatSwitchCard( + motion: motion, + outgoing: true, child: CustomPaint( painter: ChatTapeExit( image: backdrop.image!, @@ -58,47 +53,95 @@ Widget chatWorkspaceSurface({ ), ), ), - ); - }, - ), - for (final pane in ordered) - // A switch moves the retained pane view; the view itself is - // built once per layout; ticks resize its real scroll viewport. - AnimatedBuilder( - key: ValueKey('chat-workspace-${pane.id}'), - animation: motion.animation, - child: paneView(pane), - builder: (context, child) => Positioned.fromRect( - rect: - motion.rectFor(pane.id) ?? - (collapsed ? Offset.zero & size : geometry.panes[pane.id]!), - child: child!, - ), - ), - if (mobile?.peekId != null && !motion.isAnimating) - Positioned( - top: mobile!.contentHeight - 12, - left: 0, - right: 0, - height: 24, - child: ChatMobilePeekDivider( - height: mobile.rects[mobile.peekId]!.height, - available: size.height - 6, - onChanged: controller.resizeMobilePeek, - ), - ), - if (!collapsed && mobile == null) - for (final divider in geometry.dividers) - Positioned.fromRect( - key: ValueKey('chat-workspace-${divider.split.id}'), - rect: divider.rect, - child: ChatWorkspaceDivider( - geometry: divider, - onChanged: (ratio) => - controller.resize(divider.split.id, ratio), + ), + ); + }, + ) + : const SizedBox.shrink(); + final livePanes = [ + for (final pane in ordered) + // A switch moves the retained pane view; the view itself is + // built once per layout; ticks resize its real scroll viewport. + AnimatedBuilder( + key: ValueKey('chat-workspace-${pane.id}'), + animation: motion.animation, + child: paneView(pane), + builder: (context, child) => Positioned.fromRect( + rect: + motion.rectFor(pane.id) ?? + (collapsed ? Offset.zero & size : geometry.panes[pane.id]!), + child: IgnorePointer( + ignoring: + motion.isRetainedOutgoing(pane.id) || + (mobile != null + ? !mobile.rects.containsKey(pane.id) && + !motion.isRetainedOutgoing(pane.id) + : collapsed && pane.id != controller.activePaneId), + child: Opacity( + opacity: + mobile != null && + !mobile.rects.containsKey(pane.id) && + !motion.isRetainedOutgoing(pane.id) + ? 0 + : motion.opacityFor(pane.id), + child: ChatSwitchCard( + motion: motion, + outgoing: motion.isRetainedOutgoing(pane.id), + child: child!, ), ), - ], + ), + ), + ), + ]; + return ChatPanePicture( + key: backdrop.pictureKey, + child: AnimatedBuilder( + animation: motion.animation, + builder: (context, _) => Stack( + fit: StackFit.expand, + clipBehavior: Clip.hardEdge, + children: [ + if (mobile != null) + ColoredBox( + color: usesCupertinoHost(context) + ? CupertinoTheme.of(context).scaffoldBackgroundColor + : Theme.of(context).colorScheme.surface, + ), + picture, + for (final pane in livePanes) + if (motion.isTape || + pane.key != ValueKey('chat-workspace-${motion.topPaneId}')) + pane, + if (!motion.isTape) + for (final pane in livePanes) + if (pane.key == ValueKey('chat-workspace-${motion.topPaneId}')) + pane, + if (mobile?.peekId != null && !motion.isAnimating) + Positioned( + top: mobile!.contentHeight - 12, + left: 0, + right: 0, + height: 24, + child: ChatMobilePeekDivider( + height: mobile.rects[mobile.peekId]!.height, + available: size.height - 6, + onChanged: controller.resizeMobilePeek, + ), + ), + if (!collapsed && mobile == null) + for (final divider in geometry.dividers) + Positioned.fromRect( + key: ValueKey('chat-workspace-${divider.split.id}'), + rect: divider.rect, + child: ChatWorkspaceDivider( + geometry: divider, + onChanged: (ratio) => + controller.resize(divider.split.id, ratio), + ), + ), + ], + ), ), ); } diff --git a/app/notes/quick-switch-animation-options.md b/app/notes/quick-switch-animation-options.md new file mode 100644 index 00000000..90f15339 --- /dev/null +++ b/app/notes/quick-switch-animation-options.md @@ -0,0 +1,35 @@ +# Quick-switch animation options + +Settings → Animations now offers Tape (existing default), Swap and Card stack. +The choice is device-local and restored before the normal app starts. All modes +share the 560 ms clock, the existing global speed factor and reduced-motion +handling. A style change applies to the next exchange, without changing a +transition already in progress. + +Swap moves retained live chat viewports between positions. Card stack adds a +sideward lift, perspective, depth and shadow, with the outgoing card painted in +front for the first half and behind the incoming card for the second. A third +added pane fades into the preview; only added panes participate. No duplicate +live chat tree is created. Drafts, real scroll constraints and saved split axes +remain intact. The end-of-animation rebuild retires the outgoing third pane. + +Checks: +- Focused workspace tests: 32 passed, /tmp/memwatch/out.LxkEa8. +- Workspace/settings/motion integration: 179 passed, /tmp/memwatch/out.jbBm8y. +- Earlier broad chat/settings/motion suite: 1115 passed, /tmp/memwatch/out.6VISrw. +- Analyzer clean, flutter-analyze.mJLrNC. +- Browser fixture built with Flutter web. Capture kit interactions selected and + restored the settings, filmed two- and three-pane Card stack, cycled another + added pane and unfolded to three horizontal panes. Material dark and Cupertino + light reviewed; final capture reports contain no browser errors. +- Reviewed: /tmp/review/switch-card-final/01-choices.png, + 03-film-label-Expand-Fixture-chat-1-sheet.png, + 05-film-label-Expand-Fixture-chat-2-sheet.png, 06-three-panes.png, + 08-unfolded.png; /tmp/review/switch-swap-cupertino/02-selected-swap.png and + 03-film-label-Expand-Fixture-chat-1-sheet.png. +- Earlier capture attempts used obsolete fixture labels; corrected to the + fixture's actual titles and completed the flows. The shared fixture entry + now restores animation preferences just as the normal bootstrap does. +- No Android device connected. No on-device verification or installation. + Existing narrow-pane header clipping is visible in the wide capture and is + outside this change. diff --git a/app/test/features/chat/workspace/chat_switch_styles_test.dart b/app/test/features/chat/workspace/chat_switch_styles_test.dart new file mode 100644 index 00000000..018a1f4b --- /dev/null +++ b/app/test/features/chat/workspace/chat_switch_styles_test.dart @@ -0,0 +1,171 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.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'; +import 'package:pipelines_app/features/chat/workspace/chat_switch_card.dart'; + +Widget _host(ChatWorkspaceController controller, {bool reduced = false}) => + MaterialApp( + home: MediaQuery( + data: MediaQueryData(disableAnimations: reduced), + child: ChatWorkspace( + controller: controller, + singlePane: true, + mobilePeeks: true, + paneBuilder: (_, pane, active) => + _Draft(key: ValueKey(pane.sessionId)), + ), + ), + ); + +class _Draft extends StatefulWidget { + const _Draft({super.key}); + @override + State<_Draft> createState() => _DraftState(); +} + +class _DraftState extends State<_Draft> { + final controller = TextEditingController(); + @override + void dispose() { + controller.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) => + Material(child: TextField(controller: controller)); +} + +const _peekTop = (800 - 6) * .8 + 6; +Finder rect(String pane) => find.byKey(ValueKey('chat-workspace-$pane')); +void main() { + void phone(WidgetTester tester) { + tester.view.physicalSize = const Size(560, 800); + tester.view.devicePixelRatio = 1; + tester.platformDispatcher.accessibilityFeaturesTestValue = + const FakeAccessibilityFeatures(disableAnimations: false); + addTearDown(tester.platformDispatcher.clearAccessibilityFeaturesTestValue); + addTearDown(tester.view.reset); + } + + for (final style in [ + QuickSwitchAnimation.swap, + QuickSwitchAnimation.cardStack, + ]) { + testWidgets('${style.name} exchanges depth without recreating drafts', ( + tester, + ) async { + phone(tester); + SharedPreferences.setMockInitialValues({}); + await QuickSwitchAnimationController.instance.setAnimation(style); + addTearDown( + () => QuickSwitchAnimationController.instance.setAnimation( + QuickSwitchAnimation.tape, + ), + ); + final controller = ChatWorkspaceController()..open('a'); + final a = controller.activePaneId!; + controller.splitActive('b', ChatSplitAxis.horizontal); + final b = controller.activePaneId!; + await tester.pumpWidget(_host(controller)); + await tester.pumpAndSettle(); + final before = tester.state<_DraftState>(find.byKey(const ValueKey('b'))); + before.controller.text = 'Keep my draft'; + controller.activate(a); + await tester.pump(); + await tester.pump(const Duration(milliseconds: 140)); + expect(find.byKey(const ValueKey('chat-tape-exit')), findsNothing); + expect(find.byKey(const ValueKey('chat-swap-exit')), findsNothing); + Stack surface() => tester.widget( + find.ancestor(of: rect(a), matching: find.byType(Stack)).first, + ); + expect(surface().children.last.key, ValueKey('chat-workspace-$b')); + final card = tester.widget( + find + .descendant( + of: find.byWidgetPredicate( + (w) => w is ChatSwitchCard && w.outgoing, + ), + matching: find.byType(Transform), + ) + .first, + ); + expect( + card.transform.entry(3, 2) != 0, + style == QuickSwitchAnimation.cardStack, + ); + await tester.pump(const Duration(milliseconds: 210)); + expect( + surface().children.indexWhere( + (w) => w.key == ValueKey('chat-workspace-$b'), + ), + lessThan( + surface().children.indexWhere( + (w) => w.key == ValueKey('chat-workspace-$a'), + ), + ), + ); + await tester.pumpAndSettle(); + expect(tester.state(find.byKey(const ValueKey('b'))), same(before)); + expect(before.controller.text, 'Keep my draft'); + expect(tester.getRect(rect(a)).top, 0); + expect(tester.getRect(rect(b)).top, _peekTop); + expect(find.byKey(const ValueKey('chat-swap-exit')), findsNothing); + await tester.pumpWidget(const SizedBox()); + controller.dispose(); + await QuickSwitchAnimationController.instance.setAnimation( + QuickSwitchAnimation.tape, + ); + }); + } + + testWidgets('card stack cycles all added panes and settles reduced motion', ( + tester, + ) async { + phone(tester); + SharedPreferences.setMockInitialValues({}); + await QuickSwitchAnimationController.instance.setAnimation( + QuickSwitchAnimation.cardStack, + ); + addTearDown( + () => QuickSwitchAnimationController.instance.setAnimation( + QuickSwitchAnimation.tape, + ), + ); + final controller = ChatWorkspaceController()..open('a'); + for (final id in ['b', 'c']) { + controller.splitActive(id, ChatSplitAxis.horizontal); + } + await tester.pumpWidget(_host(controller)); + await tester.pumpAndSettle(); + final states = { + for (final id in ['a', 'b', 'c']) + id: tester.state<_DraftState>( + find.byKey(ValueKey(id), skipOffstage: false), + ), + }; + for (final id in ['a', 'b', 'c', 'a']) { + final pane = controller.panes.firstWhere((p) => p.sessionId == id); + await tester.tap(find.byKey(ValueKey('chat-peek-${pane.id}'))); + await tester.pumpAndSettle(); + expect(controller.activePane!.sessionId, id); + for (final entry in states.entries) { + expect( + tester.state(find.byKey(ValueKey(entry.key), skipOffstage: false)), + same(entry.value), + ); + } + } + await tester.pumpWidget(_host(controller, reduced: true)); + controller.activate( + controller.panes.firstWhere((p) => p.sessionId == 'b').id, + ); + await tester.pump(); + expect(tester.getRect(rect(controller.activePaneId!)).top, 0); + expect(find.byKey(const ValueKey('chat-swap-exit')), findsNothing); + await tester.pumpWidget(const SizedBox()); + controller.dispose(); + }); +} diff --git a/app/tool/search_selection_probe_entry.dart b/app/tool/search_selection_probe_entry.dart index 7ec51e16..1ac3c700 100644 --- a/app/tool/search_selection_probe_entry.dart +++ b/app/tool/search_selection_probe_entry.dart @@ -1,4 +1,6 @@ import 'health_probe_fixture.dart'; +import 'package:pipelines_app/ui/motion/quick_switch_animation.dart'; +import 'package:pipelines_app/ui/motion/animation_speed.dart'; // Standalone fixture entry for real-browser Search result-selection evidence. // // Build and probe (from app/): @@ -725,8 +727,12 @@ class _FixtureSink implements WebSocketSink { /// `ThemeMode.system` follows (omitted: the browser's color scheme). /// /// app/tool/capture/ drives this entry generically; see its README. -void main() { +Future main() async { WidgetsFlutterBinding.ensureInitialized(); + await Future.wait([ + QuickSwitchAnimationController.instance.restore(), + AnimationSpeedController.instance.restore(), + ]); final params = fixtureParams(); installHostProbes(params); // `?connect=1` (native only) opens the real launch flow with no saved