Promote active mobile chats immediately and composite a short reveal

This commit is contained in:
2026-11-06 22:08:42 +00:00
parent af1c9eb98c
commit cad9bbd0f7
3 changed files with 162 additions and 59 deletions
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/workspace/chat_workspace.dart';
@@ -30,6 +31,7 @@ class _Draft extends StatefulWidget {
class _DraftState extends State<_Draft> {
final controller = TextEditingController();
int layouts = 0;
@override
void dispose() {
controller.dispose();
@@ -37,14 +39,43 @@ class _DraftState extends State<_Draft> {
}
@override
Widget build(BuildContext context) =>
Material(child: TextField(controller: controller));
Widget build(BuildContext context) => Material(
child: _LayoutCounter(
onLayout: () => layouts++,
child: TextField(controller: controller),
),
);
}
class _LayoutCounter extends SingleChildRenderObjectWidget {
const _LayoutCounter({required this.onLayout, required super.child});
final VoidCallback onLayout;
@override
RenderObject createRenderObject(BuildContext context) =>
_CountLayouts(onLayout);
@override
void updateRenderObject(
BuildContext context,
covariant _CountLayouts renderObject,
) {
renderObject.onLayout = onLayout;
}
}
class _CountLayouts extends RenderProxyBox {
_CountLayouts(this.onLayout);
VoidCallback onLayout;
@override
void performLayout() {
onLayout();
super.performLayout();
}
}
Finder _rect(String pane) => find.byKey(ValueKey('chat-workspace-$pane'));
void main() {
testWidgets(
'mobile peeks animate80/20 and retain drafts and saved geometry',
'active chat promotes to top with cheap reveal and stable thread layout',
(tester) async {
tester.view.physicalSize = const Size(560, 800);
tester.view.devicePixelRatio = 1;
@@ -75,40 +106,42 @@ void main() {
expect(oldHeight, closeTo((800 - 6) * .2, 1));
expect(tester.getSize(_rect(second)).height, closeTo((800 - 6) * .8, 1));
await tester.pumpAndSettle();
final positionState = tester.state(_rect(first));
await tester.tap(find.byKey(ValueKey('chat-peek-$first')));
expect(
controller.activePane?.sessionId,
'a',
reason: 'tap activates peek immediately',
reason: 'tap activates immediately',
);
await tester.pump();
expect(tester.state(_rect(first)), same(positionState));
await tester.pump(const Duration(milliseconds: 100));
expect(
tester.widget<AnimatedPositioned>(_rect(first)).duration,
const Duration(milliseconds: 220),
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));
final aLayouts = (aState as _DraftState).layouts;
final bLayouts = (bState as _DraftState).layouts;
await tester.pump(const Duration(milliseconds: 60));
final reveal = tester.widget<FadeTransition>(
find.byKey(ValueKey('chat-reveal-$first')),
);
final intermediate = tester.getSize(_rect(first)).height;
expect(intermediate, greaterThan(oldHeight));
expect(intermediate, lessThan((800 - 6) * .8));
// Content follows the animated viewport, rather than jumping to the
// target height and leaving a blank area during the transition.
expect(reveal.opacity.value, greaterThan(.75));
expect(reveal.opacity.value, lessThan(1));
// The short animation only composites retained content. In particular,
// neither transcript nor composer receives a new size on each tick.
expect(
tester.getSize(find.byKey(const ValueKey('a'))).height,
closeTo(intermediate, 1),
closeTo((800 - 6) * .8, 1),
);
final shrinkingHeight = tester.getSize(_rect(second)).height;
expect(
tester.getSize(find.byKey(const ValueKey('b'))).height,
closeTo(shrinkingHeight < 300 ? 300 : shrinkingHeight, 1),
closeTo((800 - 6) * .8, 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 as _DraftState).controller.text, 'Draft b');
expect(bState.controller.text, 'Draft b');
expect(
tester
.widget<EditableText>(
@@ -121,8 +154,22 @@ void main() {
.hasFocus,
isFalse,
);
controller.activate(second);
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();
await tester.tap(find.byKey(ValueKey('chat-peek-$second')));
await tester.pumpAndSettle();
expect(tester.getRect(_rect(second)).top, 0);
expect(
tester
.widget<FadeTransition>(find.byKey(ValueKey('chat-reveal-$second')))
.opacity
.value,
1,
);
expect(controller.snapshot()!.encode(), saved);
await tester.pumpWidget(_host(controller, mobile: false));
await tester.pumpAndSettle();
@@ -152,6 +199,14 @@ void main() {
controller.activate(first);
await tester.pump();
expect(tester.getSize(_rect(first)).height, closeTo((800 - 6) * .8, 1));
expect(tester.getRect(_rect(first)).top, 0);
expect(
tester
.widget<FadeTransition>(find.byKey(ValueKey('chat-reveal-$first')))
.opacity
.value,
1,
);
expect(find.byType(_Draft), findsNWidgets(2));
expect(find.byType(_Draft, skipOffstage: false), findsNWidgets(3));
controller.activate(third);