Cycle mobile tape through added panes and retain horizontal unfold layout

This commit is contained in:
2026-11-07 16:10:05 +00:00
parent 329005abe3
commit 9c67415c22
6 changed files with 126 additions and 22 deletions
@@ -10,24 +10,21 @@ class ChatMobilePanes {
ChatMobilePanes({
required List<ChatWorkspacePane> panes,
required String activeId,
required String? peekId,
required Size size,
double peekFraction = .2,
}) {
final active = panes.firstWhere((pane) => pane.id == activeId);
this.activeId = active.id;
final peek =
panes
.where((pane) => pane.id == peekId && pane.id != activeId)
.firstOrNull ??
panes.where((pane) => pane.id != activeId).firstOrNull;
// A stable circular order reaches every added pane. Choosing the last
// active here would trap repeated taps in a two-chat toggle.
final index = panes.indexWhere((pane) => pane.id == activeId);
final peek = panes.length > 1 ? panes[(index + 1) % panes.length] : null;
if (peek == null) {
contentHeight = size.height;
rects[active.id] = Offset.zero & size;
return;
}
this.peekId = peek.id;
this.activeId = active.id;
peekId = peek.id;
const gap = 6.0;
final available = math.max(0.0, size.height - gap);
final maximum = available * .2;
@@ -14,7 +14,7 @@ class ChatPaneSwitchMotion {
);
static const Duration duration = Duration(milliseconds: 560);
static const Curve curve = Cubic(.4, 0, .2, 1);
static const Curve curve = _TapeEase();
final AnimationController _controller;
Animation<double> get animation => _controller.view;
final Map<String, Animation<double>> _reveals = {};
@@ -25,6 +25,7 @@ class ChatPaneSwitchMotion {
Size? _size;
String? _activeId;
String? _outgoingId;
String? _enteringPeekId;
Rect? outgoingSourceRect;
bool get isAnimating => _controller.isAnimating;
double get _progress => curve.transform(_controller.value);
@@ -52,7 +53,8 @@ class ChatPaneSwitchMotion {
if (travel) {
_outgoingId = _activeId;
outgoingSourceRect = _to[_outgoingId];
final peek = rects.values.firstWhere((rect) => rect.top > 0);
_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};
@@ -62,7 +64,7 @@ class ChatPaneSwitchMotion {
} else if (!mapEquals(rects, _to) || !animate) {
_from = _to = rects;
_activeId = activeId;
_outgoingId = null;
_outgoingId = _enteringPeekId = null;
outgoingSourceRect = null;
_barFrom = _barTo = {
for (final id in rects.keys) id: id == activeId ? 1 : 0,
@@ -76,7 +78,7 @@ class ChatPaneSwitchMotion {
_from = _to = const {};
_barFrom = _barTo = const {};
_size = null;
_activeId = _outgoingId = null;
_activeId = _outgoingId = _enteringPeekId = null;
outgoingSourceRect = null;
_controller.value = 1;
}
@@ -84,9 +86,10 @@ class ChatPaneSwitchMotion {
Rect? rectFor(String id) {
final to = _to[id];
if (to == null) return null;
if (_outgoingId == id && outgoingSourceRect != null) {
// The old active's snapshot owns its top exit. Its single live tree is
// already a true small viewport and loops in from below the screen.
if (_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.
final gap = to.top - _to[_activeId]!.bottom;
return to.translate(0, (_size!.height + gap - to.top) * (1 - _progress));
}
@@ -103,6 +106,14 @@ class ChatPaneSwitchMotion {
void dispose() => _controller.dispose();
}
/// Quintic easing has zero velocity and acceleration at both ends: the tape
/// picks up speed gradually and brakes without a sudden snap near the finish.
class _TapeEase extends Curve {
const _TapeEase();
@override
double transformInternal(double t) => t * t * t * (t * (6 * t - 15) + 10);
}
class _PaneReveal extends Animation<double> {
_PaneReveal(this.motion, this.id);
final ChatPaneSwitchMotion motion;
@@ -56,7 +56,6 @@ class _ChatWorkspaceState extends State<ChatWorkspace>
ChatWorkspaceGeometry? _geometry;
String? _lastActiveId;
Set<String> _visibleSessionIds = const {};
String? _peekId;
late final ChatPaneBackdrop _backdrop;
void _backdropChanged() {
if (mounted) setState(() {});
@@ -172,14 +171,12 @@ class _ChatWorkspaceState extends State<ChatWorkspace>
: widget.controller.activePaneId;
final switching = _lastActiveId != activeId;
if (switching) {
_peekId = _lastActiveId;
_lastActiveId = activeId;
}
final mobile = widget.mobilePeeks && activeId != null
final mobile = widget.mobilePeeks && collapsed && activeId != null
? ChatMobilePanes(
panes: panes,
activeId: activeId,
peekId: _peekId,
size: constraints.biggest,
peekFraction: widget.controller.mobilePeekFraction,
)
@@ -261,7 +258,7 @@ class _ChatWorkspaceState extends State<ChatWorkspace>
() => FocusScopeNode(debugLabel: pane.id),
),
onFocusChange: (focused) {
if (focused && !widget.mobilePeeks) {
if (focused && mobile == null) {
widget.controller.activate(pane.id);
}
},