Add quick switch motion library with true deck exchanges

This commit is contained in:
2026-11-07 19:36:48 +00:00
parent fc4aa1652f
commit 3b44c49679
7 changed files with 277 additions and 44 deletions
@@ -1,8 +1,8 @@
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';
import '../../../ui/motion/quick_switch_effect.dart';
/// A vertical tape or a live card exchange, selected once for each transition.
/// Tape uses an outgoing picture; swaps move the retained chats themselves.
@@ -33,7 +33,7 @@ class ChatPaneSwitchMotion {
QuickSwitchAnimation get style => _style;
bool get isTape => _style == QuickSwitchAnimation.tape;
double get progress => _progress;
bool get outgoingOnTop => !isTape && _progress < .5;
bool get outgoingOnTop => quickSwitchOutgoingOnTop(_style, _progress);
bool isRetainedOutgoing(String id) =>
isAnimating && !isTape && id == _outgoingId;
String? get topPaneId => outgoingOnTop ? _outgoingId : _activeId;
@@ -102,6 +102,12 @@ class ChatPaneSwitchMotion {
_controller.value = 1;
}
/// Stable content constraints for paint-only movement during a switch.
/// The outgoing card keeps its source viewport; incoming/preview cards use
/// their destination viewport. At rest this is the actual visible rectangle.
Rect? viewportRectFor(String id) =>
isRetainedOutgoing(id) ? outgoingSourceRect : _to[id] ?? rectFor(id);
Rect? rectFor(String id) {
final to = _to[id];
if (isRetainedOutgoing(id)) return exitingRect;
@@ -113,7 +119,13 @@ class ChatPaneSwitchMotion {
final gap = to.top - _to[_activeId]!.bottom;
return to.translate(0, (_size!.height + gap - to.top) * (1 - _progress));
}
return Rect.lerp(_from[id] ?? to, to, _progress);
return quickSwitchRect(
_style,
_progress,
_from[id] ?? to,
to,
outgoing: false,
);
}
Rect? get exitingRect {
@@ -122,13 +134,7 @@ class ChatPaneSwitchMotion {
if (!isAnimating || source == null || incoming == null) return null;
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,
);
return quickSwitchRect(_style, _progress, source, target, outgoing: true);
}
void dispose() => _controller.dispose();
@@ -1,8 +1,7 @@
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 '../../../ui/motion/quick_switch_effect.dart';
import 'chat_pane_switch_motion.dart';
/// Perspective affects paint only. The retained chat keeps its real viewport
@@ -20,33 +19,33 @@ class ChatSwitchCard extends StatelessWidget {
@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 pose = quickSwitchPose(
motion.style,
motion.isAnimating ? motion.progress : 1,
outgoing: outgoing,
);
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),
return LayoutBuilder(
builder: (context, constraints) => Opacity(
opacity: pose.opacity,
child: Transform(
alignment: Alignment.center,
transform: pose.transform(constraints.biggest),
child: DecoratedBox(
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: shadow.withValues(alpha: .24 * pose.shadow),
blurRadius: 22 * pose.shadow,
offset: Offset(0, 8 * pose.shadow),
),
],
),
],
child: child,
),
),
child: child,
),
);
}
@@ -28,6 +28,7 @@ class ChatWorkspace extends StatefulWidget {
this.shortcutsEnabled = true,
this.singlePane = false,
this.mobilePeeks = false,
this.animationStyle,
this.paneTitle,
this.onVisibleSessionIdsChanged,
});
@@ -38,6 +39,7 @@ class ChatWorkspace extends StatefulWidget {
/// Keeps the retained layout while presenting only the active chat.
final bool singlePane;
final bool mobilePeeks;
final QuickSwitchAnimation? animationStyle;
final String Function(ChatWorkspacePane)? paneTitle;
final ValueChanged<Set<String>>? onVisibleSessionIdsChanged;
@@ -187,7 +189,8 @@ class _ChatWorkspaceState extends State<ChatWorkspace>
if (mobile != null &&
switching &&
animate &&
QuickSwitchAnimationController.instance.value ==
(widget.animationStyle ??
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.
@@ -202,7 +205,9 @@ class _ChatWorkspaceState extends State<ChatWorkspace>
activeId: activeId!,
switching: switching,
animate: animate,
style: QuickSwitchAnimationController.instance.value,
style:
widget.animationStyle ??
QuickSwitchAnimationController.instance.value,
);
}
_reportVisible({