Phone chat peek: transcript-only peek, tap-or-scroll, animated switch

The inactive (peek) pane no longer shows the chat's bar: ChatPanePresentation
tells the conversation its role and ChatPaneBarReveal keeps a resting peek's
bar offstage (zero height, not painted), so the peek reads its transcript from
the top. A drag on the peek scrolls that transcript; a tap anywhere on it,
even over a button or link, activates the chat (ChatPeekTapRecognizer accepts
on release ahead of the arena sweep and yields to drags past the slop). The
'chat-peek-<id>' semantics stay a labelled button.

Switching animates (260 ms, Cubic(.2,.8,.2,1)): the tapped chat rises over the
active one with its bottom edge pinned, then the covered chat slides up into
the slot from the bottom edge; each bar fades and slides in or out over the
rise. Content boxes keep their fixed size, so ticks move and clip retained
pictures without laying a transcript out again. Reduced motion jumps. The
old focus stripe is gone.
This commit is contained in:
2026-11-07 01:17:38 +00:00
parent f4ba2ab25e
commit 357affe207
8 changed files with 832 additions and 224 deletions
@@ -1,8 +1,8 @@
import 'package:flutter/semantics.dart';
import 'dart:math' as math;
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../ui/sessions/chat_adaptive.dart';
import 'package:flutter/semantics.dart';
import 'package:flutter/widgets.dart';
import '../conversation/chat_pane_presentation.dart';
import 'chat_peek_gesture.dart';
import 'chat_workspace_controller.dart';
/// A phone presentation only: saved split axes and ratios are left untouched.
@@ -14,6 +14,7 @@ class ChatMobilePanes {
required Size size,
}) {
final active = panes.firstWhere((pane) => pane.id == activeId);
this.activeId = active.id;
final peek =
panes
.where((pane) => pane.id == peekId && pane.id != activeId)
@@ -25,6 +26,7 @@ class ChatMobilePanes {
return;
}
this.peekId = peek.id;
this.activeId = active.id;
const gap = 6.0;
final available = math.max(0.0, size.height - gap);
final peekHeight = available * .2;
@@ -41,147 +43,85 @@ class ChatMobilePanes {
late final double contentHeight;
final rects = <String, Rect>{};
String? peekId;
String? activeId;
/// [panes] with the active one last: it is drawn over the other during a
/// switch and takes pointers first.
List<ChatWorkspacePane> paintOrder(List<ChatWorkspacePane> panes) => [
for (final pane in panes)
if (pane.id != activeId) pane,
for (final pane in panes)
if (pane.id == activeId) pane,
];
}
/// Both mobile threads retain the same full content layout. Selection changes
/// positions once; only a tiny focus cue animates, so transcript layout, scroll
/// anchoring and backdrop painting do not repeat on every animation tick.
class ChatMobilePaneViewport extends StatefulWidget {
/// One retained chat in the phone presentation.
///
/// Both chats keep the same full content box ([contentHeight]), aligned to
/// the pane's top and clipped to it, so a switch moves and clips retained
/// pictures without laying a transcript out again. The peek shows its
/// transcript from the top (its bar steps aside through
/// [ChatPanePresentation]); a drag on it scrolls that transcript and a tap
/// activates the chat. The tree keeps one shape in both roles, so a chat
/// changing role keeps its state.
class ChatMobilePaneViewport extends StatelessWidget {
const ChatMobilePaneViewport({
super.key,
required this.peek,
required this.active,
required this.animate,
required this.barReveal,
required this.child,
required this.onActivate,
required this.label,
required this.paneId,
this.contentHeight,
});
final bool peek;
final bool active;
final bool animate;
/// The bar's reveal for this pane's role (see [ChatPanePresentation]).
final Animation<double> barReveal;
final Widget child;
final VoidCallback onActivate;
final String label;
final String paneId;
final double? contentHeight;
@override
State<ChatMobilePaneViewport> createState() => _ChatMobilePaneViewportState();
}
class _ChatMobilePaneViewportState extends State<ChatMobilePaneViewport>
with SingleTickerProviderStateMixin {
late final AnimationController _reveal;
late final CurvedAnimation _accent;
@override
void initState() {
super.initState();
_reveal = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 120),
value: 1,
);
_accent = CurvedAnimation(parent: _reveal, curve: Curves.easeOutCubic);
}
@override
void didUpdateWidget(covariant ChatMobilePaneViewport oldWidget) {
super.didUpdateWidget(oldWidget);
if (!widget.animate || !widget.active) {
_reveal.value = 1;
} else if (!oldWidget.active) {
_reveal.forward(from: 0);
}
}
@override
void dispose() {
_accent.dispose();
_reveal.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) => ClipRect(
child: Stack(
fit: StackFit.expand,
children: [
OverflowBox(
child: Semantics(
key: ValueKey('chat-peek-$paneId'),
identifier: peek ? 'chat-peek-$paneId' : null,
container: peek,
sortKey: peek ? const OrdinalSortKey(1) : null,
label: peek ? 'Expand $label' : null,
button: peek ? true : null,
onTap: peek ? onActivate : null,
child: ChatPeekGesture(
onTap: peek ? onActivate : null,
child: OverflowBox(
alignment: Alignment.topCenter,
minHeight: widget.contentHeight,
maxHeight: widget.contentHeight,
minHeight: contentHeight,
maxHeight: contentHeight,
child: SizedBox(
height: widget.contentHeight,
height: contentHeight,
child: ExcludeFocus(
excluding: widget.peek,
excluding: peek,
child: ExcludeSemantics(
excluding: widget.peek,
child: IgnorePointer(
ignoring: widget.peek,
child: RepaintBoundary(child: widget.child),
),
),
),
),
),
if (widget.peek)
Semantics(
key: ValueKey('chat-peek-${widget.paneId}'),
identifier: 'chat-peek-${widget.paneId}',
container: true,
sortKey: const OrdinalSortKey(1),
label: 'Expand ${widget.label}',
button: true,
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: widget.onActivate,
),
),
if (widget.active && widget.animate)
Positioned(
left: 0,
right: 0,
top: 0,
height: 2,
child: IgnorePointer(
child: RepaintBoundary(
child: CustomPaint(
key: ValueKey('chat-focus-accent-${widget.paneId}'),
painter: ChatPaneFocusAccent(
progress: _accent,
color:
chatControlsStyleOf(context) ==
ChatControlsStyle.cupertino
? CupertinoTheme.of(context).primaryColor
: Theme.of(context).colorScheme.primary,
excluding: peek,
child: RepaintBoundary(
child: ChatPanePresentation(
peek: peek,
barReveal: barReveal,
child: child,
),
),
),
),
),
],
),
),
),
);
}
/// Only this tiny focus stripe repaints during the transition; the rich chat
/// body remains opaque and stationary, avoiding a full-pane alpha/saveLayer.
class ChatPaneFocusAccent extends CustomPainter {
ChatPaneFocusAccent({required this.progress, required this.color})
: super(repaint: progress);
final Animation<double> progress;
final Color color;
@override
void paint(Canvas canvas, Size size) {
if (progress.value >= 1) return;
canvas.drawRect(
Offset.zero & size,
Paint()..color = color.withValues(alpha: (1 - progress.value) * .7),
);
}
@override
bool shouldRepaint(covariant ChatPaneFocusAccent oldDelegate) =>
oldDelegate.color != color || oldDelegate.progress != progress;
}