diff --git a/app/lib/ui/motion/container_transform_flight.dart b/app/lib/ui/motion/container_transform_flight.dart index f8a1b377..6dbead2e 100644 --- a/app/lib/ui/motion/container_transform_flight.dart +++ b/app/lib/ui/motion/container_transform_flight.dart @@ -229,11 +229,14 @@ class _Frame { required bool tracking, }) { const curve = Curves.fastOutSlowIn; - // Played backwards in time, the same easing reads as the item settling. + // Closing reads `t` from 1 to 0, so easeIn of `t` is a shrink that + // decelerates in time and starts on the first frame. The time-reversed + // fastOutSlowIn barely moved for its first ~60 ms, which read as Back + // doing nothing. final grown = tracking ? t : closing - ? curve.flipped.transform(t) + ? Curves.easeInCubic.transform(t) : curve.transform(t); // Opening covers the item first and shows the page late; closing hides // the page first and uncovers the item late. diff --git a/app/notes/chat-back-start.md b/app/notes/chat-back-start.md new file mode 100644 index 00000000..5a6d17be --- /dev/null +++ b/app/notes/chat-back-start.md @@ -0,0 +1,54 @@ +# Chat Back starts immediately (phone) + +## Finding + +Static reading of the phone chat path (`DetailPageHost`, `ContainerTransformPageRoute`, +`ContainerTransformFlight`, the chat screen's `_back`, the shell's back handling) found no +awaited work before the pop. Draft, scroll and transcript saves run fire-and-forget or in +`dispose`, after the reverse animation. `DetailPageHost`'s `onClosed` runs when the route is +disposed, so it cannot delay the pop. + +The delay the user sees is the close curve. Closing used `Curves.fastOutSlowIn.flipped` +against the animation value, which barely moves for its first ~60 ms. The page sat still +after Back, then began to shrink. + +## Change + +`lib/ui/motion/container_transform_flight.dart`: the closing shrink uses +`Curves.easeInCubic.transform(t)` on the reverse animation value. That is a shrink that starts +on the first frame and decelerates into the row. Opening is unchanged. The reverse duration +stays at `Motion.containerTransformReverse` = 250 ms (≤300 ms). + +## Measured (widget test, fake frame clock, 390x844, 16 ms per frame) + +Share of the page's shrink travel completed after each frame following the system Back +(`handlePopRoute` then `pump`). The first frame after the pop only starts the ticker, so it +reads 0 in both builds. + +| Elapsed after pop | Before | After | +| --- | ---: | ---: | +| 16 ms | 0.0% | 0.0% | +| 32 ms | 1.0% | 15.7% | +| 48 ms | 4.6% | 30.7% | +| 64 ms | 12.1% | 44.1% | +| 80 ms | 25.2% | 56.4% | + +The Back route is no longer current, and its animation is `reverse`, after the first pump +in both builds. Route change was already synchronous. + +## Focused tests + +Command: `tool/memwatch/full.sh 'test/ui/motion/container_transform_back_start_test.dart test/ui/motion/container_transform_route_test.dart test/shell/detail_page_test.dart test/features/chat/chat_open_transition_test.dart'` +Result: 15 passed, 0 failed (peak 1284 MB, 11 s). + +- New regression `container_transform_back_start_test.dart`: system Back changes the route + in one pump, and the page is more than 10% shrunk 16 ms later. The owner's close work + awaits a future that never completes, and Back still starts. Against the old curve this + test fails (shrink 0.99%). +- `tool/analyze.sh`: clean. + +## Not verified + +- `tool/chat_back_latency_probe.mjs` (browser) was not run; UI capture belongs to ui-review. +- Phone device timing was not measured (no device test ran). +- Leaving the chat list (tab-root Back) was read, not measured: it calls `_select` synchronously. diff --git a/app/test/ui/motion/container_transform_back_start_test.dart b/app/test/ui/motion/container_transform_back_start_test.dart new file mode 100644 index 00000000..455c8c41 --- /dev/null +++ b/app/test/ui/motion/container_transform_back_start_test.dart @@ -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 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 neverSaved = Completer(); + int closed = 0; + + @override + void dispose() { + page.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) => ValueListenableBuilder( + 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 _save() => neverSaved.future; +} + +Future _pumpOwner( + WidgetTester tester, + ValueNotifier 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(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); + }, + ); +}