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.
This commit is contained in:
@@ -94,55 +94,45 @@ class _FadeThroughStackState extends State<FadeThroughStack>
|
||||
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]),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user