WIP: fade-through tab transitions (run #228)

This commit is contained in:
2026-11-01 17:15:17 +00:00
parent 8687f0fc0d
commit c385a1f72b
6 changed files with 192 additions and 22 deletions
@@ -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<PipelineDetailPanel> {
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<PipelineDetailPanel> {
showIdentity: !inBar,
),
),
PipelineDetailTab.graph => BelowTopBar(
BelowTopBar(
child: PipelineGraphTab(
detail: detail,
selectedStage: _graphSelection,
@@ -185,8 +187,8 @@ class _PipelineDetailPanelState extends State<PipelineDetailPanel> {
_openGraphStage(context, detail, stageKey),
),
),
PipelineDetailTab.source => _source(context, detail),
},
_source(context, detail),
],
),
),
),
@@ -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<RunDetailTabs> {
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) {
+19 -12
View File
@@ -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<RunVisitPane> {
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),
),
],
),
),
);
+2 -1
View File
@@ -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<AdaptiveShell> {
);
}
Widget _destinationStack(List<Widget> contents) => IndexedStack(
Widget _destinationStack(List<Widget> contents) => FadeThroughStack(
key: _destinationStackKey,
index: AppDestination.values.indexOf(_selected),
children: contents,
+150
View File
@@ -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<Widget> children;
@override
State<FadeThroughStack> createState() => _FadeThroughStackState();
}
class _FadeThroughStackState extends State<FadeThroughStack>
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,
),
),
);
}
}
+9
View File
@@ -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);