Reduce quick switch layout churn and flatten planar depth transforms
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
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/workspace/chat_motion_viewport.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('paint resizing does not repeatedly lay out the transcript', (
|
||||
tester,
|
||||
) async {
|
||||
var layouts = 0;
|
||||
var height = 600.0;
|
||||
Size? fixed = const Size(300, 600);
|
||||
late StateSetter update;
|
||||
final transcript = LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
layouts++;
|
||||
return SizedBox(
|
||||
key: const Key('transcript'),
|
||||
width: constraints.maxWidth,
|
||||
height: constraints.maxHeight,
|
||||
);
|
||||
},
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: StatefulBuilder(
|
||||
builder: (context, setState) {
|
||||
update = setState;
|
||||
return Align(
|
||||
alignment: Alignment.topLeft,
|
||||
child: SizedBox(
|
||||
width: 300,
|
||||
height: height,
|
||||
child: ChatMotionViewport(size: fixed, child: transcript),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
final initial = layouts;
|
||||
for (final next in [480.0, 360.0, 180.0]) {
|
||||
update(() => height = next);
|
||||
await tester.pump();
|
||||
expect(tester.getSize(find.byKey(const Key('transcript'))).height, 600);
|
||||
}
|
||||
expect(layouts, initial);
|
||||
update(() => fixed = null);
|
||||
await tester.pump();
|
||||
expect(tester.getSize(find.byKey(const Key('transcript'))).height, 180);
|
||||
expect(layouts, initial + 1);
|
||||
});
|
||||
|
||||
testWidgets('chrome can fade without changing its occupied layout height', (
|
||||
tester,
|
||||
) async {
|
||||
tester.platformDispatcher.accessibilityFeaturesTestValue =
|
||||
const FakeAccessibilityFeatures(disableAnimations: false);
|
||||
addTearDown(tester.platformDispatcher.clearAccessibilityFeaturesTestValue);
|
||||
final reveal = AnimationController(
|
||||
vsync: tester,
|
||||
duration: const Duration(milliseconds: 200),
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Align(
|
||||
alignment: Alignment.topLeft,
|
||||
child: ChatPanePresentation(
|
||||
peek: false,
|
||||
fixedChromeLayout: true,
|
||||
barReveal: reveal,
|
||||
child: ChatPaneBarReveal(
|
||||
bar: const SizedBox(width: 100, height: 48),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
final bar = find.byType(ChatPaneBarReveal);
|
||||
expect(tester.getSize(bar).height, 48);
|
||||
reveal.forward();
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 60));
|
||||
expect(reveal.value, inExclusiveRange(0, 1));
|
||||
expect(tester.getSize(bar).height, 48);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.getSize(bar).height, 48);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
reveal.dispose();
|
||||
});
|
||||
}
|
||||
@@ -75,6 +75,16 @@ void main() {
|
||||
controller.activate(a);
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 140));
|
||||
// Card paint rectangles vary, but transcripts keep their useful full
|
||||
// viewport until settling to the real small preview once.
|
||||
expect(
|
||||
tester.getSize(find.byKey(const ValueKey('a'))).height,
|
||||
closeTo((800 - 6) * .8, .01),
|
||||
);
|
||||
expect(
|
||||
tester.getSize(find.byKey(const ValueKey('b'))).height,
|
||||
closeTo((800 - 6) * .8, .01),
|
||||
);
|
||||
expect(find.byKey(const ValueKey('chat-tape-exit')), findsNothing);
|
||||
expect(find.byKey(const ValueKey('chat-swap-exit')), findsNothing);
|
||||
Stack surface() => tester.widget<Stack>(
|
||||
@@ -94,8 +104,6 @@ void main() {
|
||||
expect(
|
||||
card.transform.entry(3, 2) != 0,
|
||||
{
|
||||
QuickSwitchAnimation.cardStack,
|
||||
QuickSwitchAnimation.deckSlide,
|
||||
QuickSwitchAnimation.flip,
|
||||
QuickSwitchAnimation.rolodex,
|
||||
}.contains(style),
|
||||
@@ -116,6 +124,10 @@ void main() {
|
||||
expect(before.controller.text, 'Keep my draft');
|
||||
expect(tester.getRect(rect(a)).top, 0);
|
||||
expect(tester.getRect(rect(b)).top, _peekTop);
|
||||
expect(
|
||||
tester.getSize(find.byKey(const ValueKey('b'))).height,
|
||||
closeTo((800 - 6) * .2, .01),
|
||||
);
|
||||
expect(find.byKey(const ValueKey('chat-swap-exit')), findsNothing);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
controller.dispose();
|
||||
|
||||
@@ -46,6 +46,37 @@ void main() {
|
||||
}
|
||||
});
|
||||
|
||||
test(
|
||||
'flat deck depth keeps the same projection on the cheaper affine path',
|
||||
() {
|
||||
for (final depth in [-18.0, 0.0, 18.0]) {
|
||||
final pose = QuickSwitchPose(
|
||||
translation: const Offset(-.7, .04),
|
||||
rotationZ: -.04,
|
||||
depth: depth,
|
||||
scale: .96,
|
||||
);
|
||||
final original = Matrix4.identity()
|
||||
..setEntry(3, 2, .0012)
|
||||
..translateByDouble(-.7 * 560, .04 * 635, depth, 1)
|
||||
..rotateZ(-.04)
|
||||
..scaleByDouble(.96, .96, .96, 1);
|
||||
final affine = pose.transform(full.size);
|
||||
expect(affine.entry(3, 2), 0);
|
||||
for (final point in [
|
||||
Offset.zero,
|
||||
const Offset(560, 635),
|
||||
const Offset(280, 320),
|
||||
]) {
|
||||
final expected = MatrixUtils.transformPoint(original, point);
|
||||
final actual = MatrixUtils.transformPoint(affine, point);
|
||||
expect(actual.dx, closeTo(expected.dx, .000001));
|
||||
expect(actual.dy, closeTo(expected.dy, .000001));
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
test('all choices have finite bounded geometry throughout a transition', () {
|
||||
for (final style in QuickSwitchAnimation.values) {
|
||||
for (final outgoing in [true, false]) {
|
||||
|
||||
Reference in New Issue
Block a user