Merge: fade-through tab transitions
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
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 = active || outgoing;
|
||||
final progress = _controller.value;
|
||||
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 - 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: ExcludeFocus(
|
||||
excluding: !active,
|
||||
child: ExcludeSemantics(
|
||||
excluding: !active,
|
||||
child: Transform.scale(
|
||||
scale: scale,
|
||||
child: Opacity(opacity: opacity, child: widget.children[index]),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
/// Duration of each tab's entrance pop.
|
||||
static const Duration tabEntranceDuration = Duration(milliseconds: 260);
|
||||
|
||||
|
||||
@@ -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'}),
|
||||
|
||||
@@ -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 = <String>[];
|
||||
|
||||
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<Opacity>(
|
||||
find.ancestor(
|
||||
of: find.text('page $name'),
|
||||
matching: find.byType(Opacity),
|
||||
),
|
||||
)
|
||||
.opacity;
|
||||
|
||||
bool _onstage(WidgetTester tester, String name) => !tester
|
||||
.widget<Offstage>(
|
||||
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);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user