From c385a1f72b72f40d295f1d5471687845adebeba1 Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Sun, 1 Nov 2026 17:15:17 +0000 Subject: [PATCH 1/2] WIP: fade-through tab transitions (run #228) --- .../widgets/pipeline_detail_panel.dart | 14 +- app/lib/features/runs/ui/run_detail_tabs.dart | 7 +- .../features/runs/ui/run_detail_visit.dart | 31 ++-- app/lib/shell/adaptive_shell.dart | 3 +- app/lib/ui/motion/fade_through_stack.dart | 150 ++++++++++++++++++ app/lib/ui/motion/motion.dart | 9 ++ 6 files changed, 192 insertions(+), 22 deletions(-) create mode 100644 app/lib/ui/motion/fade_through_stack.dart diff --git a/app/lib/features/pipelines/widgets/pipeline_detail_panel.dart b/app/lib/features/pipelines/widgets/pipeline_detail_panel.dart index 7f4e2e98..9db03117 100644 --- a/app/lib/features/pipelines/widgets/pipeline_detail_panel.dart +++ b/app/lib/features/pipelines/widgets/pipeline_detail_panel.dart @@ -16,6 +16,7 @@ import '../pipelines_controller.dart'; import '../ui/run_pipeline_action.dart'; import 'pipeline_controls.dart'; import '../../../ui/text/markdown_source_view.dart'; +import '../../../ui/motion/fade_through_stack.dart'; import 'pipeline_detail_styles.dart'; import 'pipeline_graph_tab.dart'; import 'pipeline_summary_view.dart'; @@ -167,9 +168,10 @@ class _PipelineDetailPanelState extends State { child: FloatingBarOverlay( edge: edge, bar: tabs, - child: Builder( - builder: (context) => switch (_tab) { - PipelineDetailTab.summary => _scrolling( + child: FadeThroughStack( + index: PipelineDetailTab.values.indexOf(_tab), + children: [ + _scrolling( PipelineSummaryView( controller: _controller, detail: detail, @@ -177,7 +179,7 @@ class _PipelineDetailPanelState extends State { showIdentity: !inBar, ), ), - PipelineDetailTab.graph => BelowTopBar( + BelowTopBar( child: PipelineGraphTab( detail: detail, selectedStage: _graphSelection, @@ -185,8 +187,8 @@ class _PipelineDetailPanelState extends State { _openGraphStage(context, detail, stageKey), ), ), - PipelineDetailTab.source => _source(context, detail), - }, + _source(context, detail), + ], ), ), ), diff --git a/app/lib/features/runs/ui/run_detail_tabs.dart b/app/lib/features/runs/ui/run_detail_tabs.dart index 82f194b3..06ea11d0 100644 --- a/app/lib/features/runs/ui/run_detail_tabs.dart +++ b/app/lib/features/runs/ui/run_detail_tabs.dart @@ -1,6 +1,7 @@ import '../../../ui/adaptive/floating_bar_layout.dart'; import '../../../ui/adaptive/segmented_bar.dart'; import '../../../ui/adaptive/top_glass_strip.dart'; +import '../../../ui/motion/fade_through_stack.dart'; import 'dart:math' as math; import 'package:flutter/cupertino.dart'; @@ -374,10 +375,10 @@ class _RunDetailTabsState extends State { selected: shown, onSelected: (tab) => setState(() => _tab = tab), ); - final body = KeyedSubtree( + final body = FadeThroughStack( key: ValueKey('run-detail-body-${widget.run['id']}'), - // Every tab fills the pane, on a phone and an unfolded foldable alike. - child: _body(shown), + index: tabs.indexOf(shown), + children: [for (final tab in tabs) _body(tab)], ); if (edge == FloatingBarEdge.top && constraints.maxWidth >= kRunDetailWideChromeMinWidth) { diff --git a/app/lib/features/runs/ui/run_detail_visit.dart b/app/lib/features/runs/ui/run_detail_visit.dart index 504fadbe..2a4205f0 100644 --- a/app/lib/features/runs/ui/run_detail_visit.dart +++ b/app/lib/features/runs/ui/run_detail_visit.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import '../../../core/api_gateway.dart'; import '../../../ui/adaptive/floating_bar_layout.dart'; +import '../../../ui/motion/fade_through_stack.dart'; import 'run_detail_content.dart'; import 'run_detail_visit_facts_view.dart'; import 'run_detail_visit_sections.dart'; @@ -73,18 +74,24 @@ class _RunVisitPaneState extends State { onSelected: (section) => setState(() => _section = section), ), // Every section fills the page, on a phone and an unfolded foldable. - child: runVisitSectionBody( - section: _section, - run: widget.run, - step: widget.step, - visitIndex: widget.visitIndex, - stageKey: widget.visit.stage, - runSteps: widget.runSteps, - gateway: widget.gateway, - onRunChanged: widget.onRunChanged, - configuredEndpoint: widget.configuredEndpoint, - cupertino: widget.cupertino, - facts: RunVisitFactsView(step: widget.step), + child: FadeThroughStack( + index: shownVisitSections.indexOf(visitTabFor(_section)), + children: [ + for (final section in shownVisitSections) + runVisitSectionBody( + section: section, + run: widget.run, + step: widget.step, + visitIndex: widget.visitIndex, + stageKey: widget.visit.stage, + runSteps: widget.runSteps, + gateway: widget.gateway, + onRunChanged: widget.onRunChanged, + configuredEndpoint: widget.configuredEndpoint, + cupertino: widget.cupertino, + facts: RunVisitFactsView(step: widget.step), + ), + ], ), ), ); diff --git a/app/lib/shell/adaptive_shell.dart b/app/lib/shell/adaptive_shell.dart index 365928b3..c8fba5d6 100644 --- a/app/lib/shell/adaptive_shell.dart +++ b/app/lib/shell/adaptive_shell.dart @@ -1,4 +1,5 @@ import '../ui/motion/motion.dart'; +import '../ui/motion/fade_through_stack.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -316,7 +317,7 @@ class _AdaptiveShellState extends State { ); } - Widget _destinationStack(List contents) => IndexedStack( + Widget _destinationStack(List contents) => FadeThroughStack( key: _destinationStackKey, index: AppDestination.values.indexOf(_selected), children: contents, diff --git a/app/lib/ui/motion/fade_through_stack.dart b/app/lib/ui/motion/fade_through_stack.dart new file mode 100644 index 00000000..04998f7b --- /dev/null +++ b/app/lib/ui/motion/fade_through_stack.dart @@ -0,0 +1,150 @@ +import 'package:flutter/widgets.dart'; + +import 'motion.dart'; + +/// Keeps every child mounted while fading between two indexed pages. +/// +/// Unlike [AnimatedSwitcher], this never removes a page after it has been +/// visited, so scroll positions, controllers and local state remain owned by +/// their original element tree. +class FadeThroughStack extends StatefulWidget { + const FadeThroughStack({ + super.key, + required this.index, + required this.children, + }); + + final int index; + final List children; + + @override + State createState() => _FadeThroughStackState(); +} + +class _FadeThroughStackState extends State + with SingleTickerProviderStateMixin { + late final AnimationController _controller = AnimationController( + vsync: this, + duration: Motion.tabFadeThrough, + ); + late int _visibleIndex = widget.index; + int? _outgoingIndex; + + @override + void initState() { + super.initState(); + _controller.value = 1; + _controller.addStatusListener(_statusChanged); + } + + @override + void didUpdateWidget(covariant FadeThroughStack oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.index == oldWidget.index) return; + // A focused control must not remain focused after its page becomes + // inactive; otherwise keyboard traversal can still reach the old tab. + FocusManager.instance.primaryFocus?.unfocus( + disposition: UnfocusDisposition.scope, + ); + final duration = Motion.of(context, Motion.tabFadeThrough); + _controller.duration = duration; + if (duration == Duration.zero) { + _outgoingIndex = null; + _visibleIndex = widget.index; + _controller.value = 1; + return; + } + _outgoingIndex = _visibleIndex; + _visibleIndex = widget.index; + _controller.forward(from: 0); + } + + void _statusChanged(AnimationStatus status) { + if (status != AnimationStatus.completed || !mounted) return; + setState(() => _outgoingIndex = null); + } + + @override + void dispose() { + _controller.removeStatusListener(_statusChanged); + _controller.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + final reduced = Motion.of(context, Motion.tabFadeThrough) == Duration.zero; + if (reduced) { + _outgoingIndex = null; + _visibleIndex = widget.index; + _controller.value = 1; + } + return AnimatedBuilder( + animation: _controller, + builder: (context, _) => Stack( + fit: StackFit.expand, + children: [ + for (var index = 0; index < widget.children.length; index++) + _page(index, reduced), + ], + ), + ); + } + + Widget _page(int index, bool reduced) { + final outgoing = index == _outgoingIndex; + final active = index == _visibleIndex; + final shown = reduced || active || outgoing; + final progress = _controller.value; + final opacity = outgoing + ? 1 - + CurvedAnimation( + parent: _controller, + curve: const Interval( + 0, + Motion.tabFadeThroughIncomingAt, + curve: Motion.curve, + ), + ).value + : active + ? CurvedAnimation( + parent: _controller, + curve: const Interval( + Motion.tabFadeThroughIncomingAt, + 1, + curve: Motion.curve, + ), + ).value + : 0.0; + final scale = outgoing + ? 1 - + (Motion.tabFadeThroughScale - 1).abs() * + (progress / Motion.tabFadeThroughIncomingAt).clamp(0.0, 1.0) + : active + ? Motion.tabFadeThroughScale + + (1 - Motion.tabFadeThroughScale) * + ((progress - Motion.tabFadeThroughIncomingAt) / + (1 - Motion.tabFadeThroughIncomingAt)) + .clamp(0.0, 1.0) + : 1.0; + final transformed = Transform.scale( + scale: scale, + child: Opacity(opacity: opacity, child: widget.children[index]), + ); + final page = active + ? Semantics(container: true, explicitChildNodes: true, child: transformed) + : ExcludeFocus( + child: ExcludeSemantics(child: transformed), + ); + return Offstage( + offstage: !shown, + child: TickerMode( + enabled: active, + child: IgnorePointer( + ignoring: !active, + child: page, + ), + ), + ); + } +} diff --git a/app/lib/ui/motion/motion.dart b/app/lib/ui/motion/motion.dart index 67059a18..0f4e7f2f 100644 --- a/app/lib/ui/motion/motion.dart +++ b/app/lib/ui/motion/motion.dart @@ -10,6 +10,15 @@ abstract final class Motion { /// A section opening or closing, a bar changing its actions. static const Duration standard = Duration(milliseconds: 200); + /// The total duration of a tab's Material fade-through transition. + static const Duration tabFadeThrough = Duration(milliseconds: 250); + + /// The scale at the midpoint of a tab's fade-through transition. + static const double tabFadeThroughScale = 0.96; + + /// The point at which the incoming tab begins to appear. + static const double tabFadeThroughIncomingAt = 0.35; + /// Delay between neighbouring controls entering as one group. static const Duration tabEntranceStagger = Duration(milliseconds: 40); From b56a2eb72daad5cea0da40a918abce72b6fb5cc7 Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Sun, 1 Nov 2026 17:27:05 +0000 Subject: [PATCH 2/2] Fade-through tab transitions, kept state and tests (finishes run #228) Tabs fade through when switching main destinations and page tabs. Each page keeps one widget structure whatever its state, so its element (scroll, controllers, text) survives switches; curves are computed directly instead of building a CurvedAnimation per frame; only the active and outgoing pages are on stage, including under reduced motion. Adds FadeThroughStack tests. --- app/lib/ui/motion/fade_through_stack.dart | 72 ++++------ .../attention_badge_wiring_test.dart | 4 +- .../ui/motion/fade_through_stack_test.dart | 132 ++++++++++++++++++ 3 files changed, 166 insertions(+), 42 deletions(-) create mode 100644 app/test/ui/motion/fade_through_stack_test.dart diff --git a/app/lib/ui/motion/fade_through_stack.dart b/app/lib/ui/motion/fade_through_stack.dart index 04998f7b..5b425b44 100644 --- a/app/lib/ui/motion/fade_through_stack.dart +++ b/app/lib/ui/motion/fade_through_stack.dart @@ -94,55 +94,45 @@ class _FadeThroughStackState extends State Widget _page(int index, bool reduced) { final outgoing = index == _outgoingIndex; final active = index == _visibleIndex; - final shown = reduced || active || outgoing; + final shown = active || outgoing; final progress = _controller.value; - final opacity = outgoing - ? 1 - - CurvedAnimation( - parent: _controller, - curve: const Interval( - 0, - Motion.tabFadeThroughIncomingAt, - curve: Motion.curve, - ), - ).value - : active - ? CurvedAnimation( - parent: _controller, - curve: const Interval( - Motion.tabFadeThroughIncomingAt, - 1, - curve: Motion.curve, - ), - ).value - : 0.0; + const split = Motion.tabFadeThroughIncomingAt; + // Curves evaluated directly: a CurvedAnimation built per frame would + // register a listener on the controller every frame. + final out = const Interval( + 0, + split, + curve: Motion.curve, + ).transform(progress); + final into = const Interval( + split, + 1, + curve: Motion.curve, + ).transform(progress); + const shrink = 1 - Motion.tabFadeThroughScale; + final opacity = outgoing ? 1 - out : (active ? into : 0.0); final scale = outgoing - ? 1 - - (Motion.tabFadeThroughScale - 1).abs() * - (progress / Motion.tabFadeThroughIncomingAt).clamp(0.0, 1.0) - : active - ? Motion.tabFadeThroughScale + - (1 - Motion.tabFadeThroughScale) * - ((progress - Motion.tabFadeThroughIncomingAt) / - (1 - Motion.tabFadeThroughIncomingAt)) - .clamp(0.0, 1.0) - : 1.0; - final transformed = Transform.scale( - scale: scale, - child: Opacity(opacity: opacity, child: widget.children[index]), - ); - final page = active - ? Semantics(container: true, explicitChildNodes: true, child: transformed) - : ExcludeFocus( - child: ExcludeSemantics(child: transformed), - ); + ? 1 - shrink * out + : (active ? Motion.tabFadeThroughScale + shrink * into : 1.0); + // The same widget structure for every page whatever its state, so a + // page's element (and its scroll position, controllers and text) is kept + // across switches. return Offstage( offstage: !shown, child: TickerMode( enabled: active, child: IgnorePointer( ignoring: !active, - child: page, + child: ExcludeFocus( + excluding: !active, + child: ExcludeSemantics( + excluding: !active, + child: Transform.scale( + scale: scale, + child: Opacity(opacity: opacity, child: widget.children[index]), + ), + ), + ), ), ), ); diff --git a/app/test/application/attention_badge_wiring_test.dart b/app/test/application/attention_badge_wiring_test.dart index 107efc18..2ee9e9d4 100644 --- a/app/test/application/attention_badge_wiring_test.dart +++ b/app/test/application/attention_badge_wiring_test.dart @@ -58,7 +58,9 @@ void main() { await tester.pump(); expect(provider.value.uri.path, '/pipelines'); await waitForRequest(tester, channel, 'list_pipelines'); - expect(find.text('Nightly build'), findsNothing); + // The Runs page may still be fading out, but it is no longer the + // active page: nothing on it takes a tap. + expect(find.text('Nightly build').hitTestable(), findsNothing); channel.incoming.add( jsonEncode({'type': 'run_event', 'run_id': 1, 'status': 'waiting'}), diff --git a/app/test/ui/motion/fade_through_stack_test.dart b/app/test/ui/motion/fade_through_stack_test.dart new file mode 100644 index 00000000..053c4846 --- /dev/null +++ b/app/test/ui/motion/fade_through_stack_test.dart @@ -0,0 +1,132 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/ui/motion/fade_through_stack.dart'; +import 'package:pipelines_app/ui/motion/motion.dart'; + +class _Page extends StatefulWidget { + const _Page(this.name); + final String name; + @override + State<_Page> createState() => _PageState(); +} + +class _PageState extends State<_Page> { + final controller = TextEditingController(); + @override + void dispose() { + controller.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) => Column( + children: [ + Text('page ${widget.name}'), + TextField(key: Key('field ${widget.name}'), controller: controller), + ElevatedButton( + key: Key('button ${widget.name}'), + onPressed: () => tapped.add(widget.name), + child: Text('tap ${widget.name}'), + ), + ], + ); +} + +final tapped = []; + +Widget _host(int index, {bool reduced = false}) => MaterialApp( + home: MediaQuery( + data: MediaQueryData(disableAnimations: reduced), + child: Scaffold( + body: FadeThroughStack( + index: index, + children: const [_Page('a'), _Page('b'), _Page('c')], + ), + ), + ), +); + +double _opacityOf(WidgetTester tester, String name) => tester + .widget( + find.ancestor( + of: find.text('page $name'), + matching: find.byType(Opacity), + ), + ) + .opacity; + +bool _onstage(WidgetTester tester, String name) => !tester + .widget( + find + .ancestor( + of: find.text('page $name', skipOffstage: false), + matching: find.byType(Offstage, skipOffstage: false), + ) + .first, + ) + .offstage; + +void main() { + setUp(tapped.clear); + + testWidgets('fades the old page out, then the new page in', (tester) async { + await tester.pumpWidget(_host(0)); + await tester.pumpWidget(_host(1)); + final total = Motion.tabFadeThrough; + await tester.pump(total * 0.2); + expect(_opacityOf(tester, 'a'), inExclusiveRange(0.0, 1.0)); + expect(_opacityOf(tester, 'b'), 0.0); + await tester.pump(total * 0.5); + expect(_opacityOf(tester, 'a'), 0.0); + expect(_opacityOf(tester, 'b'), inExclusiveRange(0.0, 1.0)); + await tester.pump(total); + expect(_opacityOf(tester, 'b'), 1.0); + expect(_onstage(tester, 'a'), isFalse); + }); + + testWidgets('a page keeps its state across switches', (tester) async { + await tester.pumpWidget(_host(0)); + await tester.enterText(find.byKey(const Key('field a')), 'draft'); + final before = tester.state(find.byType(_Page).first); + await tester.pumpWidget(_host(1)); + await tester.pump(Motion.tabFadeThrough * 2); + await tester.pumpWidget(_host(0)); + await tester.pump(Motion.tabFadeThrough * 2); + expect(tester.state(find.byType(_Page).first), same(before)); + expect(find.text('draft'), findsOneWidget); + }); + + testWidgets('only the active page takes taps', (tester) async { + await tester.pumpWidget(_host(0)); + await tester.pumpWidget(_host(1)); + await tester.pump(Motion.tabFadeThrough * 0.2); + // The outgoing page is still visible but must not take the tap; it + // reaches the active page's button underneath instead. + await tester.tap(find.byKey(const Key('button a')), warnIfMissed: false); + expect(tapped, isNot(contains('a'))); + expect(tapped, ['b']); + }); + + testWidgets('rapid switching ends with only the last page shown', ( + tester, + ) async { + await tester.pumpWidget(_host(0)); + await tester.pumpWidget(_host(1)); + await tester.pump(const Duration(milliseconds: 30)); + await tester.pumpWidget(_host(2)); + await tester.pump(const Duration(milliseconds: 30)); + await tester.pumpWidget(_host(0)); + await tester.pump(Motion.tabFadeThrough * 2); + expect(_onstage(tester, 'a'), isTrue); + expect(_onstage(tester, 'b'), isFalse); + expect(_onstage(tester, 'c'), isFalse); + expect(_opacityOf(tester, 'a'), 1.0); + }); + + testWidgets('reduced motion switches instantly', (tester) async { + await tester.pumpWidget(_host(0, reduced: true)); + await tester.pumpWidget(_host(1, reduced: true)); + await tester.pump(); + expect(_opacityOf(tester, 'b'), 1.0); + }); +}