Animate mobile chat swaps as overlapping raised cards

This commit is contained in:
2026-11-07 12:38:11 +00:00
parent 414a74e0c9
commit 19958e81c5
5 changed files with 125 additions and 7 deletions
@@ -0,0 +1,38 @@
import 'package:flutter/material.dart';
/// A raised foreground while phone chats cross. The transcript still lays out
/// at its real animated height, so the settled peek can reach its final row.
class ChatPaneSwapCard extends StatelessWidget {
const ChatPaneSwapCard({
super.key,
required this.enabled,
required this.lift,
required this.child,
});
final bool enabled;
final double lift;
final Widget child;
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final amount = enabled ? lift : 0.0;
final radius = BorderRadius.circular(16 * amount);
return DecoratedBox(
decoration: BoxDecoration(
color: enabled ? theme.colorScheme.surface : null,
borderRadius: radius,
boxShadow: [
BoxShadow(
color: theme.shadowColor.withValues(alpha: .24 * amount),
blurRadius: 24 * amount,
spreadRadius: 2 * amount,
offset: Offset(0, -6 * amount),
),
],
),
child: ClipRRect(borderRadius: radius, child: child),
);
}
}
@@ -1,9 +1,10 @@
import 'dart:math' as math;
import 'dart:ui' show lerpDouble;
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
/// One continuous phone-pane swap. Both rectangles and both chrome reveals
/// follow the same ease; an interrupted swap starts at their current values.
/// One continuous phone-pane swap. Both cards travel together; the incoming card grows
/// ahead of the outgoing card shrinking. Chrome follows the shared ease; an interrupted swap starts at their current values.
/// The app's scheduler speed preference scales this ticker once globally.
class ChatPaneSwitchMotion {
ChatPaneSwitchMotion({required TickerProvider vsync})
@@ -13,7 +14,7 @@ class ChatPaneSwitchMotion {
value: 1,
);
static const Duration duration = Duration(milliseconds: 360);
static const Duration duration = Duration(milliseconds: 480);
static const Curve curve = Cubic(.22, .7, .24, 1);
final AnimationController _controller;
Animation<double> get animation => _controller.view;
@@ -23,6 +24,8 @@ class ChatPaneSwitchMotion {
Map<String, double> _barFrom = const {};
Map<String, double> _barTo = const {};
Size? _size;
String? _incomingId;
Map<String, double> _liftFrom = const {};
bool get isAnimating => _controller.isAnimating;
double get _progress => curve.transform(_controller.value);
@@ -42,12 +45,16 @@ class ChatPaneSwitchMotion {
_size = size;
if (travel) {
final ids = {..._to.keys, ...rects.keys};
_liftFrom = {for (final id in ids) id: liftFor(id)};
_from = {for (final id in ids) id: rectFor(id) ?? rects[id]!};
_barFrom = {for (final id in ids) id: _reveal(id)};
_incomingId = activeId;
_to = rects;
_barTo = {for (final id in rects.keys) id: id == activeId ? 1 : 0};
_controller.forward(from: 0);
} else if (!mapEquals(rects, _to) || !animate) {
_incomingId = null;
_liftFrom = const {};
_from = rects;
_to = rects;
_barFrom = _barTo = {
@@ -62,12 +69,34 @@ class ChatPaneSwitchMotion {
_from = _to = const {};
_barFrom = _barTo = const {};
_size = null;
_incomingId = null;
_liftFrom = const {};
_controller.value = 1;
}
Rect? rectFor(String id) {
final to = _to[id];
return to == null ? null : Rect.lerp(_from[id] ?? to, to, _progress);
if (to == null) return null;
final from = _from[id] ?? to;
final t = _progress;
// Separate travel from resizing: overlapping cards should read as passing
// over/under each other rather than collapsing into the same small strip.
final sizeT = id == _incomingId ? Curves.easeOut.transform(t) : t * t;
return Rect.fromLTWH(
lerpDouble(from.left, to.left, t)!,
lerpDouble(from.top, to.top, t)!,
lerpDouble(from.width, to.width, t)!,
lerpDouble(from.height, to.height, sizeT)!,
);
}
/// A short lift on the foreground card; interruptions keep the current
/// elevation before handing the foreground to the newly selected pane.
double liftFor(String id) {
final t = _controller.value;
final previous = (_liftFrom[id] ?? 0) * (1 - _progress);
final lift = id == _incomingId ? math.sin(math.pi * t) : 0.0;
return (previous + lift).clamp(0.0, 1.0);
}
void dispose() => _controller.dispose();
@@ -9,6 +9,7 @@ import 'chat_workspace_geometry.dart';
import 'chat_mobile_panes.dart';
import 'chat_pane_switch_motion.dart';
import 'chat_pane_backdrop.dart';
import 'chat_pane_swap_card.dart';
export 'chat_workspace_controller.dart';
export 'chat_workspace_geometry.dart' show ChatPaneDirection;
@@ -196,7 +197,11 @@ class _ChatWorkspaceState extends State<ChatWorkspace>
(collapsed
? Offset.zero & constraints.biggest
: geometry.panes[pane.id]!),
child: child!,
child: ChatPaneSwapCard(
enabled: mobile != null,
lift: _motion.liftFor(pane.id),
child: child!,
),
),
),
if (!collapsed && mobile == null)
+27
View File
@@ -0,0 +1,27 @@
# Mobile crossing-card quick switch
The incoming chat and outgoing chat exchange positions together. The incoming
card grows ahead of the outgoing one shrinking, paints in front, and lifts with
rounded corners and a theme shadow before settling flush. The default duration
is 480 ms; the global animation speed still scales its ticker once. Reduced
motion settles immediately. The existing bounded backdrop covers vacated areas.
Changed source: workspace/chat_pane_switch_motion.dart, chat_workspace.dart,
and chat_pane_swap_card.dart. The live transcript still receives its actual
animated constraints; no full-height overflow viewport was introduced.
Verification:
- `tool/memwatch/full.sh test/features/chat`: 957 passed, zero failed/skipped;
peak 2160 MB, 72 s. Log `/tmp/memwatch/out.MYOugN`.
- `tool/analyze.sh`: clean.
- Fixture web build succeeded. Browser interactions and inspected film sheets:
`/tmp/review/mobile-card-swap-light/01-film-label-Expand-Fixture-chat-1-sheet.png`
and `/tmp/review/mobile-card-swap-cupertino/01-film-label-Expand-Fixture-chat-1-sheet.png`.
- The material fixture's final small pane viewport is 198.8 px; its scroll offset
equals max (688.6), so the content bottom remains reachable.
- Regression checks cover overlapping cards, incoming paint order, retained
drafts/scroll, uninterrupted rectangle/reveal continuity when reversing, and
reduced motion. A premature role change initially caused a height jump during
reversal; current geometry is now sampled before changing the incoming role.
These are browser and widget checks, not native Android device verification.
@@ -3,6 +3,7 @@ import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/conversation/chat_pane_presentation.dart';
import 'package:pipelines_app/features/chat/workspace/chat_pane_switch_motion.dart';
import 'package:pipelines_app/features/chat/workspace/chat_pane_swap_card.dart';
import 'package:pipelines_app/features/chat/workspace/chat_workspace.dart';
import 'package:pipelines_app/ui/adaptive/segmented_bar_overlay.dart';
@@ -133,7 +134,7 @@ void main() {
}
testWidgets(
'one eased swap moves both panes, interruptions retain draft and reveal',
'crossing cards overlap with incoming on top; interruption retains state',
(tester) async {
phone(tester);
final controller = ChatWorkspaceController()..open('a');
@@ -147,7 +148,7 @@ void main() {
bState.controller.text = 'Retained draft';
controller.activate(a);
await tester.pump();
await tester.pump(const Duration(milliseconds: 90));
await tester.pump(const Duration(milliseconds: 120));
final t = ChatPaneSwitchMotion.curve.transform(.25);
expect(tester.getRect(rect(a)).top, closeTo(_peekTop * (1 - t), .5));
expect(tester.getRect(rect(b)).top, closeTo(_peekTop * t, .5));
@@ -155,6 +156,24 @@ void main() {
tester.getSize(find.byKey(const ValueKey('a'))).height,
closeTo(tester.getRect(rect(a)).height, .5),
);
final incoming = tester.getRect(rect(a));
final outgoing = tester.getRect(rect(b));
expect(incoming.overlaps(outgoing), isTrue);
expect(incoming.height + outgoing.height, greaterThan(800));
final cards = tester
.widgetList<ChatPaneSwapCard>(find.byType(ChatPaneSwapCard))
.toList();
expect(cards.last.lift, greaterThan(.5));
expect(cards.first.lift, 0);
final stack = tester.widget<Stack>(
find
.descendant(
of: find.byType(ChatWorkspace),
matching: find.byType(Stack),
)
.first,
);
expect(stack.children.last.key, ValueKey('chat-workspace-$a'));
final beforeA = tester.getRect(rect(a));
final beforeB = tester.getRect(rect(b));
double reveal(String session) => tester