Start chat back transitions immediately
Use an easing curve that visibly begins on the first reverse frame instead of leaving the phone chat page apparently still. Add a regression test and record the measured before/after latency evidence.
This commit is contained in:
@@ -0,0 +1,141 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/shell/destination.dart';
|
||||
import 'package:pipelines_app/shell/detail_page.dart';
|
||||
import 'package:pipelines_app/shell/shell_bar.dart';
|
||||
import 'package:pipelines_app/ui/motion/container_transform_flight.dart';
|
||||
import 'package:pipelines_app/ui/motion/container_transform_source.dart';
|
||||
import 'package:pipelines_app/ui/motion/motion.dart';
|
||||
|
||||
const _screen = Size(390, 844);
|
||||
|
||||
/// A phone-style owner: its selected row opens a detail page that grows from
|
||||
/// the row, as the chat screen's page does.
|
||||
class _Owner extends StatefulWidget {
|
||||
const _Owner({required this.selection, required this.sources});
|
||||
|
||||
final ValueNotifier<String?> selection;
|
||||
final ContainerTransformSources sources;
|
||||
|
||||
@override
|
||||
State<_Owner> createState() => _OwnerState();
|
||||
}
|
||||
|
||||
class _OwnerState extends State<_Owner> {
|
||||
final DetailPageHost page = DetailPageHost();
|
||||
|
||||
/// Stands in for work the owner might await when the page closes (a draft
|
||||
/// or scroll save). It never completes, so any pop that waited on it would
|
||||
/// never start.
|
||||
final Completer<void> neverSaved = Completer<void>();
|
||||
int closed = 0;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
page.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => ValueListenableBuilder<String?>(
|
||||
valueListenable: widget.selection,
|
||||
builder: (context, selected, _) {
|
||||
page.sync(
|
||||
context,
|
||||
selected: selected != null,
|
||||
destination: AppDestination.chat,
|
||||
growFrom: widget.sources.link(() => widget.selection.value),
|
||||
onClosed: () {
|
||||
closed++;
|
||||
unawaited(_save());
|
||||
widget.selection.value = null;
|
||||
},
|
||||
builder: (context) =>
|
||||
ShellBar(title: 'Chat', child: const Text('chat body')),
|
||||
);
|
||||
return ContainerTransformScope(
|
||||
sources: widget.sources,
|
||||
child: const Column(
|
||||
children: [
|
||||
SizedBox(height: 200),
|
||||
ContainerTransformSource(
|
||||
id: '7',
|
||||
color: Color(0xFFE3F2FD),
|
||||
child: SizedBox(
|
||||
key: Key('row-7'),
|
||||
height: 72,
|
||||
child: Text('row 7'),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
Future<void> _save() => neverSaved.future;
|
||||
}
|
||||
|
||||
Future<void> _pumpOwner(
|
||||
WidgetTester tester,
|
||||
ValueNotifier<String?> selection,
|
||||
ContainerTransformSources sources,
|
||||
) async {
|
||||
tester.view.physicalSize = _screen;
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: _Owner(selection: selection, sources: sources),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets(
|
||||
'system Back changes the route in one frame and shrinks the page at once',
|
||||
(tester) async {
|
||||
final selection = ValueNotifier<String?>(null);
|
||||
final sources = ContainerTransformSources();
|
||||
await _pumpOwner(tester, selection, sources);
|
||||
selection.value = '7';
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final row = tester.getRect(
|
||||
find.byKey(const Key('row-7'), skipOffstage: false),
|
||||
);
|
||||
final route = ModalRoute.of(
|
||||
tester.element(find.byKey(containerTransformSurfaceKey)),
|
||||
)!;
|
||||
expect(route.isCurrent, isTrue);
|
||||
|
||||
// The owner's close work never completes, yet Back starts at once.
|
||||
await tester.binding.handlePopRoute();
|
||||
await tester.pump();
|
||||
expect(route.isCurrent, isFalse);
|
||||
expect(route.animation!.status, AnimationStatus.reverse);
|
||||
|
||||
// Two frames after the pop the page is visibly shrinking toward the row.
|
||||
await tester.pump(const Duration(milliseconds: 16));
|
||||
final height = tester
|
||||
.getRect(find.byKey(containerTransformSurfaceKey))
|
||||
.height;
|
||||
final travel = _screen.height - row.height;
|
||||
final shrunk = (_screen.height - height) / travel;
|
||||
expect(shrunk, greaterThan(0.1));
|
||||
expect(shrunk, lessThan(1));
|
||||
|
||||
// The reverse stays within the standard Material container transform.
|
||||
expect(
|
||||
Motion.containerTransformReverse,
|
||||
lessThanOrEqualTo(const Duration(milliseconds: 300)),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('chat body'), findsNothing);
|
||||
expect(selection.value, isNull);
|
||||
expect(tester.state<_OwnerState>(find.byType(_Owner)).closed, 1);
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user