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
@@ -262,7 +262,16 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
controller: _sessionsForSidebar,
sidebarFolds: _foldsForSidebar,
excludedSessionIds: _workspace.panes.map((pane) => pane.sessionId).toSet(),
onSelected: _openBelow,
onSelected: (session) {
if (!showsListBesideDetail(context)) {
// Save a horizontal desktop layout underneath the phone tape. Keep
// the rail compact so unfolding leaves room for the panes themselves.
_setSidebarMode(ChatSidebarMode.compact);
_openBeside(session);
} else {
_openBelow(session);
}
},
);
Widget _workspaceView() => SafeArea(
@@ -273,7 +282,7 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
onVisibleSessionIdsChanged: _workspaceVisibilityChanged,
shortcutsEnabled: _workspaceVisible,
singlePane: !showsListBesideDetail(context),
mobilePeeks: !showsListBesideDetail(context),
mobilePeeks: true,
paneTitle: (pane) =>
'${_rowFor(pane.sessionId)?['title'] ?? pane.sessionId}',
onFocusPane: (pane) => _composerFocus.request(pane.sessionId),
@@ -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);
}
},
@@ -156,6 +156,10 @@ void main() {
);
final workspace = tester.widget<ChatWorkspace>(find.byType(ChatWorkspace));
expect(workspace.controller.paneCount, 2);
expect(
(workspace.controller.root as ChatWorkspaceSplit).axis,
ChatSplitAxis.horizontal,
);
expect(workspace.controller.activePane?.sessionId, 'b');
final first = workspace.controller.panes.first.id;
await tester.tap(find.byKey(ValueKey('chat-peek-$first')));
@@ -169,6 +173,25 @@ void main() {
isFalse,
);
expect(tester.state(_thread('a')), same(stateA));
tester.view.physicalSize = const Size(880, 1000);
await tester.pumpAndSettle();
final aRect = tester.getRect(
find.byKey(
ValueKey('chat-workspace-${workspace.controller.panes.first.id}'),
),
);
final bRect = tester.getRect(
find.byKey(
ValueKey('chat-workspace-${workspace.controller.panes.last.id}'),
),
);
expect(aRect.top, bRect.top);
expect(aRect.right, lessThan(bRect.left));
expect(tester.state(_thread('a')), same(stateA));
expect(
tester.widget<EditableText>(_input('a')).controller.text,
'Phone draft A',
);
expect(tester.takeException(), isNull);
});
@@ -187,6 +187,73 @@ void main() {
},
);
testWidgets('quick switch loops through four added panes and keeps drafts', (
tester,
) async {
phone(tester);
final controller = ChatWorkspaceController()..open('a');
for (final id in ['b', 'c', 'd']) {
controller.splitActive(id, ChatSplitAxis.horizontal);
}
await tester.pumpWidget(_host(controller));
await tester.pumpAndSettle();
final states = {
for (final id in ['a', 'b', 'c', 'd'])
id: tester.state<_DraftState>(
find.byKey(ValueKey(id), skipOffstage: false),
),
};
for (final entry in states.entries) {
entry.value.controller.text = 'Draft ${entry.key}';
}
for (final id in ['a', 'b', 'c', 'd', 'a', 'b', 'c', 'd']) {
final pane = controller.panes.firstWhere((pane) => pane.sessionId == id);
await tester.tap(find.byKey(ValueKey('chat-peek-${pane.id}')));
await tester.pump();
await tester.pump(const Duration(milliseconds: 140));
final incoming = tester.getRect(rect(pane.id));
final next = controller
.panes[(controller.panes.indexWhere((p) => p.id == pane.id) + 1) % 4];
final entering = tester.getRect(rect(next.id));
final exiting = tester.getRect(
find.byKey(const ValueKey('chat-tape-exit')),
);
expect(exiting.bottom + 6, closeTo(incoming.top, .5));
expect(incoming.bottom + 6, closeTo(entering.top, .5));
await tester.pumpAndSettle();
expect(controller.activePane!.sessionId, id);
expect(tester.getRect(rect(pane.id)).top, 0);
expect(tester.getRect(rect(next.id)).top, _peekTop);
}
for (final entry in states.entries) {
expect(
tester.state(find.byKey(ValueKey(entry.key), skipOffstage: false)),
same(entry.value),
);
expect(entry.value.controller.text, 'Draft ${entry.key}');
}
// The chooser can jump to a retained pane that was not the preview.
controller.activate(
controller.panes.firstWhere((p) => p.sessionId == 'b').id,
);
await tester.pumpAndSettle();
expect(controller.activePane!.sessionId, 'b');
final c = controller.panes.firstWhere((p) => p.sessionId == 'c');
expect(tester.getRect(rect(c.id)).top, _peekTop);
controller.activate(
controller.panes.firstWhere((p) => p.sessionId == 'd').id,
);
await tester.pumpAndSettle();
controller.close(controller.panes.firstWhere((p) => p.sessionId == 'a').id);
await tester.pumpAndSettle();
final b = controller.panes.firstWhere((p) => p.sessionId == 'b');
await tester.tap(find.byKey(ValueKey('chat-peek-${b.id}')));
await tester.pumpAndSettle();
expect(controller.activePane!.sessionId, 'b');
await tester.pumpWidget(const SizedBox());
controller.dispose();
});
testWidgets(
'bottom separator shrinks peek, clamps both ends and retains size',
(tester) async {