From c385a1f72b72f40d295f1d5471687845adebeba1 Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Sun, 1 Nov 2026 17:15:17 +0000 Subject: [PATCH] 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);