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
@@ -0,0 +1,122 @@
import 'package:flutter/material.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/conversation/chat_thread_view.dart';
import 'package:pipelines_app/features/chat/conversation/chat_transcript_scroll_view.dart';
import 'chat_thread_fixtures.dart';
/// The conversation's bar under a workspace presentation: shown for the
/// active chat, offstage for a resting peek (whose transcript starts at the
/// top), fading out in place while the chat is becoming the peek.
Future<void> _pump(
WidgetTester tester, {
required bool peek,
required double reveal,
}) async {
final gateway = FakeChatGateway();
addTearDown(gateway.close);
gateway.history = (_) async => chatPage([
for (var index = 0; index < 4; index++)
chatMessage(
'm$index',
index.isEven ? 'user' : 'assistant',
parts: [
{'type': 'text', 'text': 'Message $index'},
],
),
]);
gateway.subscribe = () async => const {};
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: ChatPanePresentation(
peek: peek,
barReveal: AlwaysStoppedAnimation(reveal),
child: ChatThreadView(
gateway: gateway,
sessionId: 's',
title: 'Presented',
onBack: () {},
),
),
),
),
);
await tester.pumpAndSettle();
}
void main() {
final header = find.byKey(const Key('chat-thread-header'));
double listTop(WidgetTester tester) => tester
.widget<ChatTranscriptScrollView>(
find.byKey(const ValueKey('chat-thread-s')),
)
.padding
.top;
testWidgets('the active chat shows its bar and keeps the list clear', (
tester,
) async {
await _pump(tester, peek: false, reveal: 1);
expect(header, findsOneWidget);
expect(listTop(tester), greaterThan(8));
expect(listTop(tester), closeTo(tester.getSize(header).height + 8, .5));
});
testWidgets('a resting peek keeps its bar offstage and reads from the top', (
tester,
) async {
await _pump(tester, peek: true, reveal: 0);
expect(header, findsNothing);
expect(
find.byKey(const Key('chat-thread-header'), skipOffstage: false),
findsOneWidget,
);
expect(listTop(tester), 8);
expect(find.text('Message 0'), findsOneWidget);
});
testWidgets('a leaving bar fades in place, keeping the list clear', (
tester,
) async {
await _pump(tester, peek: true, reveal: .4);
expect(header, findsOneWidget);
expect(listTop(tester), closeTo(tester.getSize(header).height + 8, .5));
final fade = tester.widget<FadeTransition>(
find.ancestor(of: header, matching: find.byType(FadeTransition)).first,
);
expect(fade.opacity.value, .4);
expect(
find.ancestor(of: header, matching: find.byType(IgnorePointer)),
findsWidgets,
);
});
testWidgets('without a presentation the bar is itself', (tester) async {
final gateway = FakeChatGateway();
addTearDown(gateway.close);
gateway.history = (_) async => chatPage(const []);
gateway.subscribe = () async => const {};
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: ChatThreadView(
gateway: gateway,
sessionId: 's',
title: 'Alone',
onBack: () {},
),
),
),
);
await tester.pumpAndSettle();
expect(header, findsOneWidget);
Widget? child;
tester
.element(find.byType(ChatPaneBarReveal))
.visitChildren((element) => child = element.widget);
expect(child?.key, const Key('chat-thread-header'));
});
}
@@ -1,13 +1,18 @@
import 'dart:math' as math;
import 'package:flutter/material.dart';
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_workspace.dart';
import 'package:pipelines_app/features/chat/workspace/chat_mobile_panes.dart';
import 'package:pipelines_app/ui/adaptive/segmented_bar_overlay.dart';
Widget _host(
ChatWorkspaceController controller, {
bool mobile = true,
bool reduced = false,
ChatWorkspacePaneBuilder? paneBuilder,
}) => MaterialApp(
home: MediaQuery(
data: MediaQueryData(disableAnimations: reduced),
@@ -18,7 +23,9 @@ Widget _host(
controller: controller,
singlePane: mobile,
mobilePeeks: mobile,
paneBuilder: (_, pane, active) => _Draft(key: ValueKey(pane.sessionId)),
paneBuilder:
paneBuilder ??
(_, pane, active) => _Draft(key: ValueKey(pane.sessionId)),
),
),
),
@@ -73,10 +80,68 @@ class _CountLayouts extends RenderProxyBox {
}
}
/// A conversation stand-in: a bar over a list that keeps clear of it, with a
/// button as its first row.
class _Thread extends StatelessWidget {
const _Thread({
super.key,
required this.id,
required this.scroll,
required this.onPressed,
});
final String id;
final ScrollController scroll;
final VoidCallback onPressed;
@override
Widget build(BuildContext context) => Material(
child: SegmentedBarOverlay(
bar: ChatPaneBarReveal(
bar: SizedBox(key: ValueKey('bar-$id'), height: 48),
),
child: Builder(
builder: (context) => ListView(
controller: scroll,
padding: EdgeInsets.only(top: MediaQuery.paddingOf(context).top),
children: [
SizedBox(
key: ValueKey('row-$id-0'),
height: 40,
child: TextButton(
key: ValueKey('button-$id'),
onPressed: onPressed,
child: const Text('Row'),
),
),
for (var row = 1; row < 40; row++)
SizedBox(key: ValueKey('row-$id-$row'), height: 40),
],
),
),
),
);
}
const _top = (800 - 6) * .8;
const _peekTop = _top + 6;
final _duration = ChatPaneSwitchMotion.duration.inMilliseconds;
/// The rise's progress [ms] into a switch (1 once the chat has arrived).
double _rise(int ms) => ChatPaneSwitchMotion.curve.transform(
math.min(1, ms / _duration / ChatPaneSwitchMotion.riseShare),
);
/// The settle's progress [ms] into a switch (0 until the chat has arrived).
double _settle(int ms) => ChatPaneSwitchMotion.curve.transform(
math.max(
0,
(ms / _duration - ChatPaneSwitchMotion.riseShare) /
(1 - ChatPaneSwitchMotion.riseShare),
),
);
Finder _rect(String pane) => find.byKey(ValueKey('chat-workspace-$pane'));
void main() {
testWidgets(
'active chat promotes to top with small focus accent and stable thread layout',
'active chat travels to the top on the switch curve with a stable thread layout',
(tester) async {
tester.view.physicalSize = const Size(560, 800);
tester.view.devicePixelRatio = 1;
@@ -103,9 +168,9 @@ void main() {
),
'Draft b',
);
final oldHeight = tester.getSize(_rect(first)).height;
expect(oldHeight, closeTo((800 - 6) * .2, 1));
expect(tester.getSize(_rect(second)).height, closeTo((800 - 6) * .8, 1));
expect(tester.getSize(_rect(first)).height, closeTo((800 - 6) * .2, 1));
expect(tester.getRect(_rect(first)).top, closeTo(_peekTop, 1));
expect(tester.getSize(_rect(second)).height, closeTo(_top, 1));
await tester.pumpAndSettle();
await tester.tap(find.byKey(ValueKey('chat-peek-$first')));
expect(
@@ -113,49 +178,54 @@ void main() {
'a',
reason: 'tap activates immediately',
);
// The switch starts where the panes are: the tapped chat rises over
// the other, which stays put until covered.
await tester.pump();
expect(tester.getRect(_rect(first)).top, 0);
expect(tester.getSize(_rect(first)).height, closeTo((800 - 6) * .8, 1));
expect(tester.getRect(_rect(second)).top, closeTo((800 - 6) * .8 + 6, 1));
expect(tester.getRect(_rect(first)).top, closeTo(_peekTop, 1));
expect(tester.getRect(_rect(second)).top, 0);
final aLayouts = (aState as _DraftState).layouts;
final bLayouts = (bState as _DraftState).layouts;
await tester.pump(const Duration(milliseconds: 60));
final accentFinder = find.byKey(ValueKey('chat-focus-accent-$first'));
final accent =
tester.widget<CustomPaint>(accentFinder).painter!
as ChatPaneFocusAccent;
expect(tester.getSize(accentFinder).height, 2);
expect(accent.progress.value, greaterThan(0));
expect(accent.progress.value, lessThan(1));
final firstTop = tester.getRect(_rect(first)).top;
expect(firstTop, closeTo(_peekTop * (1 - _rise(60)), 1));
expect(tester.getRect(_rect(first)).bottom, 800);
expect(
find.descendant(
of: find.byType(ChatWorkspace),
matching: find.byType(FadeTransition),
),
findsNothing,
tester.getRect(_rect(second)),
const Offset(0, 0) & const Size(560, _top),
);
await tester.pump(const Duration(milliseconds: 60));
expect(tester.getRect(_rect(first)).top, lessThan(firstTop));
expect(
find.descendant(
of: find.byType(ChatWorkspace),
matching: find.byType(SlideTransition),
),
findsNothing,
tester.getRect(_rect(first)).top,
closeTo(_peekTop * (1 - _rise(120)), 1),
);
// The short animation only composites retained content. In particular,
// neither transcript nor composer receives a new size on each tick.
expect(tester.getRect(_rect(second)).top, 0);
// The run only composites retained content: neither transcript nor
// composer receives a new size on any tick.
expect(
tester.getSize(find.byKey(const ValueKey('a'))).height,
closeTo((800 - 6) * .8, 1),
closeTo(_top, 1),
);
expect(
tester.getSize(find.byKey(const ValueKey('b'))).height,
closeTo((800 - 6) * .8, 1),
closeTo(_top, 1),
);
expect(aState.layouts, aLayouts);
expect(bState.layouts, bLayouts);
// Arrived: the covered chat slides up into the slot from the bottom.
await tester.pump(const Duration(milliseconds: 80));
expect(tester.getRect(_rect(first)).top, 0);
expect(tester.getSize(_rect(first)).height, closeTo(_top, 1));
final secondTop = tester.getRect(_rect(second)).top;
expect(secondTop, inExclusiveRange(_peekTop, 800));
expect(secondTop, closeTo(800 - (800 - _peekTop) * _settle(200), 1));
expect(tester.getSize(_rect(second)).height, closeTo(800 - _peekTop, 1));
await tester.pump(const Duration(milliseconds: 100));
expect(tester.getRect(_rect(second)).top, closeTo(_peekTop, 1));
expect(aState.layouts, aLayouts);
expect(bState.layouts, bLayouts);
await tester.pumpAndSettle();
expect(controller.activePane?.sessionId, 'a');
expect(tester.getSize(_rect(first)).height, closeTo((800 - 6) * .8, 1));
expect(tester.state(find.byKey(const ValueKey('a'))), same(aState));
expect(tester.state(find.byKey(const ValueKey('b'))), same(bState));
expect(bState.controller.text, 'Draft b');
@@ -171,26 +241,29 @@ void main() {
.hasFocus,
isFalse,
);
// A switch that interrupts another continues from where the panes are:
// the rising chat returns to the slot while the covered one stays.
await tester.tap(find.byKey(ValueKey('chat-peek-$second')));
await tester.pump();
expect(tester.getRect(_rect(second)).top, 0);
await tester.pump(const Duration(milliseconds: 20));
await tester.tap(find.byKey(ValueKey('chat-peek-$first')));
await tester.pump(const Duration(milliseconds: 60));
final interrupted = tester.getRect(_rect(second)).top;
expect(interrupted, inExclusiveRange(0, _peekTop));
controller.activate(first);
await tester.pump();
expect(tester.getRect(_rect(second)).top, closeTo(interrupted, 1));
expect(tester.getRect(_rect(first)).top, 0);
await tester.pump(const Duration(milliseconds: 60));
expect(
tester.getRect(_rect(second)).top,
inExclusiveRange(interrupted, _peekTop),
);
expect(tester.getRect(_rect(first)).top, 0);
await tester.pumpAndSettle();
expect(tester.getRect(_rect(second)).top, closeTo(_peekTop, 1));
await tester.tap(find.byKey(ValueKey('chat-peek-$second')));
await tester.pumpAndSettle();
expect(tester.getRect(_rect(second)).top, 0);
expect(
(tester
.widget<CustomPaint>(
find.byKey(ValueKey('chat-focus-accent-$second')),
)
.painter!
as ChatPaneFocusAccent)
.progress
.value,
1,
);
expect(tester.getRect(_rect(first)).top, closeTo(_peekTop, 1));
expect(controller.snapshot()!.encode(), saved);
await tester.pumpWidget(_host(controller, mobile: false));
await tester.pumpAndSettle();
@@ -203,6 +276,7 @@ void main() {
controller.dispose();
},
);
testWidgets(
'three retained panes expose active+previous and honor reduced motion',
(tester) async {
@@ -219,17 +293,131 @@ void main() {
final third = controller.activePaneId!;
controller.activate(first);
await tester.pump();
expect(tester.getSize(_rect(first)).height, closeTo((800 - 6) * .8, 1));
// Reduced motion: the panes take their places at once.
expect(tester.getSize(_rect(first)).height, closeTo(_top, 1));
expect(tester.getRect(_rect(first)).top, 0);
expect(find.byKey(ValueKey('chat-focus-accent-$first')), findsNothing);
expect(tester.getRect(_rect(third)).top, closeTo(_peekTop, 1));
await tester.pump(const Duration(milliseconds: 100));
expect(tester.getRect(_rect(first)).top, 0);
expect(tester.getRect(_rect(third)).top, closeTo(_peekTop, 1));
expect(find.byType(_Draft), findsNWidgets(2));
expect(find.byType(_Draft, skipOffstage: false), findsNWidgets(3));
controller.activate(third);
await tester.pump();
expect(tester.getSize(_rect(third)).height, closeTo((800 - 6) * .8, 1));
expect(tester.getSize(_rect(third)).height, closeTo(_top, 1));
expect(tester.takeException(), isNull);
await tester.pumpWidget(const SizedBox());
controller.dispose();
},
);
testWidgets(
'peek shows its transcript from the top, scrolls under a drag and opens on a tap',
(tester) async {
tester.view.physicalSize = const Size(560, 800);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final scrolls = {'a': ScrollController(), 'b': ScrollController()};
addTearDown(() {
for (final scroll in scrolls.values) {
scroll.dispose();
}
});
final pressed = <String>[];
final controller = ChatWorkspaceController()..open('a');
final first = controller.activePaneId!;
controller.splitActive('b', ChatSplitAxis.horizontal);
final second = controller.activePaneId!;
Finder bar(String id) => find.byKey(ValueKey('bar-$id'));
await tester.pumpWidget(
_host(
controller,
paneBuilder: (_, pane, active) => _Thread(
key: ValueKey(pane.sessionId),
id: pane.sessionId,
scroll: scrolls[pane.sessionId]!,
onPressed: () => pressed.add(pane.sessionId),
),
),
);
await tester.pumpAndSettle();
// The active chat keeps its bar and its list clear of it; the peek has
// no bar and its list starts at the pane's top edge.
expect(bar('b'), findsOneWidget);
expect(bar('a'), findsNothing);
expect(
tester.getRect(find.byKey(const ValueKey('row-b-0'))).top,
tester.getRect(_rect(second)).top + 48,
);
expect(
tester.getRect(find.byKey(const ValueKey('row-a-0'))).top,
tester.getRect(_rect(first)).top,
);
// A drag scrolls the peek's list without opening it.
await tester.drag(
find.byKey(ValueKey('chat-peek-$first')),
const Offset(0, -40),
);
await tester.pumpAndSettle();
expect(scrolls['a']!.offset, greaterThan(0));
expect(controller.activePane?.sessionId, 'b');
// A tap, even on a button inside, opens the chat and presses nothing.
await tester.tap(find.byKey(const ValueKey('button-a')));
expect(controller.activePane?.sessionId, 'a');
expect(pressed, isEmpty);
await tester.pump();
// During the rise the leaving bar fades out in place (its list moves
// only once covered) and the arriving bar fades in over a list that
// already keeps clear of it.
await tester.pump(const Duration(milliseconds: 80));
expect(bar('b'), findsOneWidget);
expect(bar('a'), findsOneWidget);
double opacity(String id) => tester
.widget<FadeTransition>(
find
.ancestor(of: bar(id), matching: find.byType(FadeTransition))
.first,
)
.opacity
.value;
expect(opacity('b'), inExclusiveRange(0, 1));
expect(opacity('a'), inExclusiveRange(0, 1));
expect(opacity('a'), closeTo(1 - opacity('b'), .001));
expect(
tester.getRect(find.byKey(const ValueKey('row-b-0'))).top,
tester.getRect(_rect(second)).top + 48,
);
expect(
tester.getRect(find.byKey(const ValueKey('row-a-0'))).top,
tester.getRect(_rect(first)).top + 48 - scrolls['a']!.offset,
);
await tester.pumpAndSettle();
expect(bar('a'), findsOneWidget);
expect(bar('b'), findsNothing);
expect(opacity('a'), 1);
expect(
tester.getRect(find.byKey(const ValueKey('row-b-0'))).top,
tester.getRect(_rect(second)).top,
);
// The active chat's button still works.
await tester.tap(find.byKey(const ValueKey('button-a')));
await tester.pump();
expect(pressed, ['a']);
final semantics = tester.ensureSemantics();
await tester.pump();
final peek = find.byKey(ValueKey('chat-peek-$second'));
expect(
tester.getSemantics(peek),
matchesSemantics(
identifier: 'chat-peek-$second',
label: 'Expand b',
isButton: true,
hasTapAction: true,
),
);
semantics.dispose();
await tester.pumpWidget(const SizedBox());
controller.dispose();
},
);
}