Top bar: every piece pops in like the tab buttons

One shared pop (pop_entrance.dart: PopTransition, popWindow, PopEntrance)
drives the floating tab buttons and the top bar, on Motion.tabEntrance*
(0.6 -> 1, 260 ms, 70 ms stagger, ease-out-back, glass fading in).
SegmentedEntrance and the barEntrance* constants are gone.

Back, the title, the actions pill and each action pop in turn from the
leading edge (SegmentedEntrancePlanner). A lone action pops once, with its
pill. A newcomer pops alone. Rebuilds and title changes never replay it.
The shell passes published actions one by one, keyed by their screen
(actionsKey), not as one cross-fading Row. The chat thread's model and mode
are separate actions. The folder picker now uses SegmentedBar.
This commit is contained in:
2026-11-03 00:30:44 +00:00
parent 2176b396ac
commit 05798a56c8
14 changed files with 709 additions and 457 deletions
@@ -1117,40 +1117,22 @@ class _ChatThreadViewState extends State<ChatThreadView> {
// A pushed page keeps the platform's stock Back (pop this route); a
// standalone conversation calls its owner.
onBack: inShellBar ? null : widget.onBack,
// Natural width while the bar has room; past the title's share both
// controls ellipsise. A session without a mode draws no mode control,
// so no empty pill is ever drawn.
// Each control is its own action, so each pops in (and sinks) on its
// own. Natural width while the bar has room; past the title's share
// the model ellipsises, and the mode keeps its whole name until it
// would take more than half the pill. A session without a mode draws
// no mode control, so no empty pill is ever drawn.
controls: [
if (hasModel || hasMode)
LayoutBuilder(
builder: (context, constraints) => Row(
mainAxisSize: MainAxisSize.min,
children: [
if (hasModel)
Flexible(
child: ChatModelControl(
key: ValueKey<String>('chat-model-${widget.sessionId}'),
gateway: widget.gateway,
sessionId: widget.sessionId,
session: session,
onChanged: widget.onModelChanged,
answeredBy: answeredBy,
),
),
if (hasMode)
// The mode keeps its whole name until it would take more
// than half the pill; the model takes the rest.
ConstrainedBox(
constraints: BoxConstraints(
maxWidth: hasModel
? constraints.maxWidth / 2
: constraints.maxWidth,
),
child: _modeControl(),
),
],
),
if (hasModel)
ChatModelControl(
key: ValueKey<String>('chat-model-${widget.sessionId}'),
gateway: widget.gateway,
sessionId: widget.sessionId,
session: session,
onChanged: widget.onModelChanged,
answeredBy: answeredBy,
),
if (hasMode) _modeControl(),
],
);
}
@@ -2,7 +2,7 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../../core/api_gateway.dart';
import '../../data/directory_listing.dart';
import '../../../../ui/adaptive/segmented_bar.dart';
import '../sessions/chat_adaptive.dart';
import 'folder_picker_controller.dart';
import 'folder_picker_list.dart';
@@ -108,41 +108,40 @@ class _FolderPickerPageState extends State<FolderPickerPage> {
);
}
/// The app's segmented bar: Back (climbing one folder), the title, and
/// Cancel in the actions pill, each popping in like every other bar.
SegmentedBar _bar(bool cupertino) => SegmentedBar(
cupertino: cupertino,
automaticallyImplyLeading: false,
leading: SegmentedBackButton(cupertino: cupertino, onPressed: _back),
title: folderPickerTitle,
actions: [
if (cupertino)
CupertinoButton(
padding: const EdgeInsets.symmetric(horizontal: 16),
onPressed: () => Navigator.pop(context),
child: const Text('Cancel'),
)
else
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('Cancel'),
),
],
);
Widget _material(Widget body) {
return Scaffold(
appBar: AppBar(
leading: BackButton(onPressed: _back),
title: const Text(folderPickerTitle),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('Cancel'),
),
],
),
body: SafeArea(top: false, child: body),
extendBodyBehindAppBar: true,
appBar: _bar(false),
// Inset below the floating bar, which the scaffold reports as padding.
body: SafeArea(child: body),
);
}
Widget _cupertino(BuildContext context, Widget body) {
final parent = _controller.listing?.parent;
final home = _controller.home;
return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
automaticallyImplyLeading: false,
leading: CupertinoNavigationBarBackButton(
onPressed: _back,
previousPageTitle: parent == null || home == null
? 'Back'
: folderCrumbs(home, parent).last.label,
),
middle: const Text(folderPickerTitle),
trailing: CupertinoButton(
padding: EdgeInsets.zero,
onPressed: () => Navigator.pop(context),
child: const Text('Cancel'),
),
),
navigationBar: _bar(true),
child: DefaultTextStyle(
style: CupertinoTheme.of(context).textTheme.textStyle,
child: SafeArea(child: body),
+4 -11
View File
@@ -1,4 +1,3 @@
import '../ui/motion/motion.dart';
import '../ui/motion/fade_through_stack.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
@@ -285,18 +284,12 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
titleAction: spec?.titleAction,
titleSemanticLabel: spec?.titleSemanticLabel,
titleKey: spec?.titleKey,
// A screen taking the bar over brings its own actions, which pop in
// one after another; while it stays, they stay.
actionsKey: published.isEmpty ? null : _bar.ownerFor(_selected),
actions: [
if (published.isNotEmpty)
// A screen taking the bar over cross-fades its actions in.
MotionSwitcher(
child: Row(
key: ObjectKey(_bar.ownerFor(_selected)),
mainAxisSize: MainAxisSize.min,
children: [
for (final action in published) Flexible(child: action),
],
),
)
...published
// A screen whose main pill is its own field (Search) needs no
// separate Search action.
else if (onSearch != null && spec?.titleWidget == null && !page)
+17 -54
View File
@@ -3,7 +3,7 @@ import 'dart:math' as math;
import 'package:flutter/widgets.dart';
import '../motion/motion.dart';
import 'glass_pill.dart';
import 'pop_entrance.dart';
/// The animations of one floating tab bar: its tab buttons popping in one
/// after another, and the newly selected icon's bounce.
@@ -25,8 +25,7 @@ class FloatingTabMotion {
final AnimationController bounce;
int _count = 0;
final List<({Animation<double> pop, Animation<double> opacity})> _entrances =
[];
final List<PopAnimations> _entrances = [];
int _selected = 0;
/// Plays the entrance of a bar of [count] tabs, from the start, with
@@ -71,44 +70,27 @@ class FloatingTabMotion {
}
/// Tab [index]'s share of [entrance]: its pop, then its fade.
({Animation<double> pop, Animation<double> opacity}) entranceOf(int index) =>
index >= 0 && index < _entrances.length
? _entrances[index]
: (pop: kAlwaysCompleteAnimation, opacity: kAlwaysCompleteAnimation);
PopAnimations entranceOf(int index) =>
index >= 0 && index < _entrances.length ? _entrances[index] : poppedIn;
/// Splits [entrance] into each tab's window, once per entrance.
void _splitEntrance() {
_disposeEntrances();
final total = entrance.duration!.inMicroseconds;
if (total == 0) return;
final window = Motion.tabEntranceDuration.inMicroseconds;
final total = entrance.duration!;
if (total == Duration.zero) return;
for (var index = 0; index < _count; index += 1) {
final start = Motion.tabEntranceStagger.inMicroseconds * index;
final begin = (start / total).clamp(0.0, 1.0);
final end = ((start + window) / total).clamp(begin, 1.0);
final faded =
((start + window * Motion.tabEntranceOpacityPortion) / total).clamp(
begin,
1.0,
);
_entrances.add((
pop: CurvedAnimation(
parent: entrance,
curve: Interval(begin, end, curve: Curves.easeOutBack),
_entrances.add(
popWindow(
entrance,
start: Motion.tabEntranceStagger * index,
total: total,
),
opacity: CurvedAnimation(
parent: entrance,
curve: Interval(begin, faded, curve: Curves.easeOut),
),
));
);
}
}
void _disposeEntrances() {
for (final animations in _entrances) {
(animations.pop as CurvedAnimation).dispose();
(animations.opacity as CurvedAnimation).dispose();
}
_entrances.forEach(disposePopWindow);
_entrances.clear();
}
@@ -119,10 +101,8 @@ class FloatingTabMotion {
}
}
/// Tab [index]'s whole button popping in with the bar: it grows from
/// [Motion.tabEntranceScaleBegin] with a gentle overshoot, rising a little,
/// while its glass fades in through a [GlassReveal] (so the blur fades with
/// the fill instead of snapping on at the end).
/// Tab [index]'s whole button popping in with the bar: the app's shared
/// [PopTransition], its glass fading in with its blur.
class FloatingTabEntrance extends StatelessWidget {
const FloatingTabEntrance({
super.key,
@@ -136,25 +116,8 @@ class FloatingTabEntrance extends StatelessWidget {
final Widget child;
@override
Widget build(BuildContext context) {
final entrance = motion.entranceOf(index);
return AnimatedBuilder(
animation: entrance.pop,
// The reveal keeps the tab (and its badge count) announced while it
// fades in.
child: GlassReveal(opacity: entrance.opacity, child: child),
builder: (context, child) {
final pop = entrance.pop.value;
final scale =
Motion.tabEntranceScaleBegin +
(1 - Motion.tabEntranceScaleBegin) * pop;
return Transform.translate(
offset: Offset(0, (1 - pop) * Motion.tabEntranceSlideDistance),
child: Transform.scale(scale: scale, child: child),
);
},
);
}
Widget build(BuildContext context) =>
PopTransition(animations: motion.entranceOf(index), child: child);
}
/// Tab [index]'s icon, bouncing briefly when it becomes selected.
+157
View File
@@ -0,0 +1,157 @@
import 'package:flutter/widgets.dart';
import '../motion/motion.dart';
import 'glass_pill.dart';
/// One item's share of an entrance: its pop (0 -> 1, with an overshoot) and
/// its fade (0 -> 1).
typedef PopAnimations = ({Animation<double> pop, Animation<double> opacity});
/// An item that has already entered.
const PopAnimations poppedIn = (
pop: kAlwaysCompleteAnimation,
opacity: kAlwaysCompleteAnimation,
);
/// The window of [parent] (running over [total]) in which an item that
/// starts popping at [start] pops: [Motion.tabEntranceDuration] long, fading
/// in over its first [Motion.tabEntranceOpacityPortion].
///
/// The caller disposes the result with [disposePopWindow].
PopAnimations popWindow(
Animation<double> parent, {
required Duration start,
required Duration total,
}) {
final whole = total.inMicroseconds;
if (whole == 0) return poppedIn;
final from = start.inMicroseconds;
final window = Motion.tabEntranceDuration.inMicroseconds;
final begin = (from / whole).clamp(0.0, 1.0);
final end = ((from + window) / whole).clamp(begin, 1.0);
final faded = ((from + window * Motion.tabEntranceOpacityPortion) / whole)
.clamp(begin, 1.0);
return (
pop: CurvedAnimation(
parent: parent,
curve: Interval(begin, end, curve: Motion.tabEntranceCurve),
),
opacity: CurvedAnimation(
parent: parent,
curve: Interval(begin, faded, curve: Curves.easeOut),
),
);
}
/// Releases the curves of a [popWindow].
void disposePopWindow(PopAnimations animations) {
if (animations.pop case final CurvedAnimation curved) curved.dispose();
if (animations.opacity case final CurvedAnimation curved) curved.dispose();
}
/// The app's pop-in, shared by the floating tab buttons and every piece of
/// the top bar: [child] grows from [Motion.tabEntranceScaleBegin] with a
/// gentle overshoot, rising [Motion.tabEntranceSlideDistance], while it
/// fades in.
///
/// A [glass] item fades its [GlassPill] through a [GlassReveal], so the blur
/// fades with the fill instead of snapping on at the end (an opacity layer
/// would hide the backdrop from a grouped blur); anything else fades as a
/// whole. Either way it stays announced (and findable) while it fades.
class PopTransition extends StatelessWidget {
const PopTransition({
super.key,
required this.animations,
required this.child,
this.glass = true,
});
final PopAnimations animations;
final Widget child;
final bool glass;
@override
Widget build(BuildContext context) => AnimatedBuilder(
animation: animations.pop,
child: glass
? GlassReveal(opacity: animations.opacity, child: child)
: FadeTransition(
opacity: animations.opacity,
alwaysIncludeSemantics: true,
child: child,
),
builder: (context, child) {
final pop = animations.pop.value;
return Transform.translate(
offset: Offset(0, (1 - pop) * Motion.tabEntranceSlideDistance),
child: Transform.scale(
scale:
Motion.tabEntranceScaleBegin +
(1 - Motion.tabEntranceScaleBegin) * pop,
child: child,
),
);
},
);
}
/// A [PopTransition] that drives itself: [child] pops in once, after
/// [delay], when it is first built.
///
/// Rebuilding it (a new title, new neighbours, a scroll) never plays it
/// again, so a host keys its items to keep them while they stay on screen.
/// Under reduced motion, or when [play] is false, it simply appears.
class PopEntrance extends StatefulWidget {
const PopEntrance({
super.key,
required this.child,
this.delay = Duration.zero,
this.play = true,
this.glass = true,
});
final Widget child;
final Duration delay;
final bool play;
final bool glass;
@override
State<PopEntrance> createState() => _PopEntranceState();
}
class _PopEntranceState extends State<PopEntrance>
with SingleTickerProviderStateMixin {
AnimationController? _controller;
PopAnimations _animations = poppedIn;
bool _decided = false;
@override
void didChangeDependencies() {
super.didChangeDependencies();
// Decided once, on the first build: later dependency changes (a theme,
// a text scale) never replay it.
if (_decided) return;
_decided = true;
final window = Motion.of(context, Motion.tabEntranceDuration);
if (!widget.play || window == Duration.zero) return;
final total = widget.delay + window;
final controller = AnimationController(vsync: this, duration: total);
_controller = controller;
_animations = popWindow(controller, start: widget.delay, total: total);
controller.forward();
}
@override
void dispose() {
disposePopWindow(_animations);
_controller?.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) => PopTransition(
animations: _animations,
glass: widget.glass,
child: widget.child,
);
}
+117 -116
View File
@@ -3,7 +3,8 @@ import 'dart:math' as math;
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../motion/motion.dart';
import 'pop_entrance.dart';
import 'segmented_bar_entrance.dart';
import 'segmented_bar_motion.dart';
import 'segmented_bar_pieces.dart';
@@ -48,6 +49,7 @@ class SegmentedBar extends StatefulWidget
this.titleSemanticLabel,
this.titleKey,
this.actions = const [],
this.actionsKey,
this.backgroundColor,
this.pillColor,
this.foregroundColor,
@@ -93,8 +95,15 @@ class SegmentedBar extends StatefulWidget
/// The key of the title's button (or its content when not pressable).
final Key? titleKey;
/// The bar's actions, at the trailing edge in one pill; each pops in on
/// its own (see [SegmentedEntrancePlanner]).
final List<Widget> actions;
/// Who supplies [actions] (a shell's open screen): when it changes, every
/// action is new and pops in, though one has the same key as before.
final Object? actionsKey;
/// The bar's backdrop; defaults to the enclosing scaffold's background.
final Color? backgroundColor;
@@ -171,19 +180,14 @@ class _SegmentedBarState extends State<SegmentedBar> {
final _piecesBackdrop = BackdropKey();
final _expandedTitleBackdrop = BackdropKey();
/// Whether the bar's first frame is drawn. Islands built with the bar
/// enter one after another from the leading edge; an island that turns up
/// later (an action becoming available) enters at once.
bool _shown = false;
/// Whether the actions pill was there at the last build: actions that
/// arrive with the pill enter with it, not again inside it.
bool _hadActions = false;
/// When each piece pops in: in turn from the leading edge on the bar's
/// first frame, at once (or in turn with those arriving together) later.
final _entrances = SegmentedEntrancePlanner();
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) => _shown = true);
WidgetsBinding.instance.addPostFrameCallback((_) => _entrances.markShown());
}
@override
@@ -253,34 +257,31 @@ class _SegmentedBarState extends State<SegmentedBar> {
);
}
/// The actions, each keyed by its own key (or its type and place among
/// actions of that type) so one arriving or leaving leaves the others be.
/// The actions, each keyed by its identity ([segmentedActionIds]) so one
/// arriving or leaving leaves the others be, each popping in on its own.
/// Only the first shrinks (ellipsises); the rest keep their natural width
/// as inflexible (flex 0) children.
/// as inflexible (flex 0) children, up to an even share of [maxWidth] (the
/// pill's widest): a long control (a permission mode's name beside the
/// model) leaves room for the first, and icons in a narrow pane squeeze
/// together rather than overflow the pill.
List<Widget> _actionIslands(
List<Widget> actions, {
List<Widget> actions,
List<Object> ids,
List<SegmentedActionEntrance> entrances, {
required bool cupertino,
required bool play,
}) {
final seen = <Type, int>{};
return [
for (final (index, action) in actions.indexed)
Flexible(
key: ValueKey((
'segmented.action',
action.key ??
(
action.runtimeType,
seen.update(
action.runtimeType,
(n) => n + 1,
ifAbsent: () => 0,
),
),
)),
flex: index == 0 ? 1 : 0,
child: SegmentedEntrance(
play: play,
required double maxWidth,
}) => [
for (final (index, action) in actions.indexed)
Flexible(
key: ValueKey(ids[index]),
flex: index == 0 ? 1 : 0,
child: ConstrainedBox(
constraints: BoxConstraints(
maxWidth: index == 0 ? double.infinity : maxWidth / actions.length,
),
child: PopEntrance(
play: entrances[index].play,
delay: entrances[index].delay,
glass: false,
child: SegmentedPress(
cupertino: cupertino,
@@ -290,8 +291,8 @@ class _SegmentedBarState extends State<SegmentedBar> {
),
),
),
];
}
),
];
@override
Widget build(BuildContext context) {
@@ -330,99 +331,99 @@ class _SegmentedBarState extends State<SegmentedBar> {
foreground: foregroundColor,
fill: pillColor,
);
// Each island is keyed by its role, so it keeps its entrance (and plays
// none) while the bar rebuilds around it.
var order = 0;
Duration nextDelay() =>
_shown ? Duration.zero : Motion.barEntranceStagger * order++;
final leadingDelay = leading == null ? Duration.zero : nextDelay();
// Each island is keyed by its role (and each action by its identity), so
// it keeps its entrance (and plays none) while the bar rebuilds around
// it.
final hasTitle = titleWidget != null || showTitle;
final titleDelay = hasTitle ? nextDelay() : Duration.zero;
final actionsDelay = actions.isEmpty ? Duration.zero : nextDelay();
final freshActions = !_hadActions;
_hadActions = actions.isNotEmpty;
final actionIds = segmentedActionIds(actions, widget.actionsKey);
final entrances = _entrances.plan(
leading: leading != null,
title: hasTitle,
actionIds: actionIds,
);
final Widget bar = LayoutBuilder(
builder: (context, constraints) => Row(
children: [
if (leading != null) ...[
SegmentedEntrance(
key: const ValueKey('segmented.leading'),
delay: leadingDelay,
child: SegmentedPress(
cupertino: cupertino,
tint: foregroundColor,
child: SegmentedPill(
cupertino: cupertino,
fill: pillColor,
child: leading,
),
),
),
const SizedBox(width: 8),
],
Expanded(
// Only as tall as the title: a Material scaffold offers its app
// bar more height than it needs.
child: Align(
alignment: AlignmentDirectional.centerStart,
heightFactor: 1,
child: !hasTitle
? const SizedBox.shrink()
: SegmentedEntrance(
key: ValueKey(
titleWidget != null
? 'segmented.field'
: 'segmented.title',
),
delay: titleDelay,
child: _titleIsland(context, titlePill),
),
),
),
if (actions.isNotEmpty) ...[
const SizedBox(width: 8),
// The actions keep to the trailing edge at their natural width,
// so a model name shows whole while the title has room; only past
// the title's minimum share does the first action ellipsise.
ConstrainedBox(
constraints: BoxConstraints(
maxWidth: math.max(
0,
constraints.maxWidth -
(leading == null
? 0
: segmentedPieceHeight(cupertino) + 8) -
8 -
constraints.maxWidth * SegmentedBar.minTitleShare,
),
),
child: SegmentedEntrance(
key: const ValueKey('segmented.actions'),
delay: actionsDelay,
// A lone action is the whole pill, so the pill sinks when it
// is pressed; beside others, each action sinks on its own.
builder: (context, constraints) {
// The actions keep to the trailing edge at their natural width, so
// a model name shows whole while the title has room; only past the
// title's minimum share does the first action ellipsise.
final actionsMaxWidth = math.max(
0.0,
constraints.maxWidth -
(leading == null ? 0 : segmentedPieceHeight(cupertino) + 8) -
8 -
constraints.maxWidth * SegmentedBar.minTitleShare,
);
return Row(
children: [
if (leading != null) ...[
PopEntrance(
key: const ValueKey('segmented.leading'),
delay: entrances.leading,
child: SegmentedPress(
cupertino: cupertino,
tint: foregroundColor,
enabled: actions.length == 1,
child: SegmentedPill(
cupertino: cupertino,
fill: pillColor,
child: Row(
mainAxisSize: MainAxisSize.min,
children: _actionIslands(
actions,
cupertino: cupertino,
play: !freshActions,
child: leading,
),
),
),
const SizedBox(width: 8),
],
Expanded(
// Only as tall as the title: a Material scaffold offers its app
// bar more height than it needs.
child: Align(
alignment: AlignmentDirectional.centerStart,
heightFactor: 1,
child: !hasTitle
? const SizedBox.shrink()
: PopEntrance(
key: ValueKey(
titleWidget != null
? 'segmented.field'
: 'segmented.title',
),
delay: entrances.title,
child: _titleIsland(context, titlePill),
),
),
),
if (actions.isNotEmpty) ...[
const SizedBox(width: 8),
ConstrainedBox(
constraints: BoxConstraints(maxWidth: actionsMaxWidth),
child: PopEntrance(
key: const ValueKey('segmented.actions'),
delay: entrances.pill,
// A lone action is the whole pill, so the pill sinks when it
// is pressed; beside others, each action sinks on its own.
child: SegmentedPress(
cupertino: cupertino,
tint: foregroundColor,
enabled: actions.length == 1,
child: SegmentedPill(
cupertino: cupertino,
fill: pillColor,
child: Row(
mainAxisSize: MainAxisSize.min,
children: _actionIslands(
actions,
actionIds,
entrances.actions,
cupertino: cupertino,
maxWidth: actionsMaxWidth,
),
),
),
),
),
),
),
],
],
],
),
);
},
);
final background = widget._background(context);
final inset = MediaQuery.paddingOf(context).top;
@@ -0,0 +1,93 @@
import 'package:flutter/widgets.dart';
import '../motion/motion.dart';
/// The identity of each of a bar's [actions]: its own key, or its type and
/// place among actions of that type, within [group] (whoever supplied the
/// actions). An action keeps its identity, and so its entrance, while the
/// bar rebuilds; a new [group] makes every action new.
List<Object> segmentedActionIds(List<Widget> actions, Object? group) {
final seen = <Type, int>{};
return [
for (final action in actions)
(
'segmented.action',
group,
action.key ??
(
action.runtimeType,
seen.update(action.runtimeType, (n) => n + 1, ifAbsent: () => 0),
),
),
];
}
/// When an action of a bar pops in: [play] false keeps it still (it is
/// already there, or it is the whole pill and pops with it).
typedef SegmentedActionEntrance = ({bool play, Duration delay});
/// When each piece of one build of a bar pops in.
class SegmentedEntrancePlan {
const SegmentedEntrancePlan({
required this.leading,
required this.title,
required this.pill,
required this.actions,
});
final Duration leading;
final Duration title;
/// The actions pill's delay (it only pops when it is new).
final Duration pill;
final List<SegmentedActionEntrance> actions;
}
/// Decides, build by build, when the pieces of a bar pop in with the app's
/// shared pop (`PopEntrance`), [Motion.tabEntranceStagger] apart.
///
/// On the bar's first frame its pieces enter one after another from the
/// leading edge: Back, the title, the actions pill, then each action in it.
/// A piece that turns up later enters at once; actions arriving together
/// (with a new pill, or a new screen's set) still follow one another. A lone
/// action is the whole pill, so it pops with its pill and not again. A piece
/// that stays never pops again: the plan only times newcomers, and each
/// entrance decides once, when it is first built.
class SegmentedEntrancePlanner {
bool _shown = false;
bool _hadActions = false;
Set<Object> _actionIds = const {};
/// Called once the bar's first frame is drawn.
void markShown() => _shown = true;
SegmentedEntrancePlan plan({
required bool leading,
required bool title,
required List<Object> actionIds,
}) {
var order = 0;
Duration next() => Motion.tabEntranceStagger * order++;
Duration piece() => _shown ? Duration.zero : next();
final leadingDelay = leading ? piece() : Duration.zero;
final titleDelay = title ? piece() : Duration.zero;
final freshPill = actionIds.isNotEmpty && !_hadActions;
final pillDelay = freshPill ? next() : Duration.zero;
final lone = actionIds.length == 1;
final actions = [
for (final id in actionIds)
if (_actionIds.contains(id) || (freshPill && lone))
(play: false, delay: Duration.zero)
else
(play: true, delay: next()),
];
_hadActions = actionIds.isNotEmpty;
_actionIds = actionIds.toSet();
return SegmentedEntrancePlan(
leading: leadingDelay,
title: titleDelay,
pill: pillDelay,
actions: actions,
);
}
}
@@ -3,106 +3,6 @@ import 'package:flutter/material.dart';
import 'package:flutter/physics.dart';
import '../motion/motion.dart';
import 'glass_pill.dart';
/// One island of a [SegmentedBar] (a pill, or an action inside one) popping
/// in: it grows from [Motion.barEntranceScaleBegin] with a gentle overshoot
/// while it fades in, after [delay].
///
/// It plays once, when the island is first built; rebuilding it (a new
/// title, new actions, a scroll) does not play it again, so the bar keys
/// its islands to keep them while they stay on screen. Under reduced motion,
/// or when [play] is false, the island simply appears.
///
/// A [glass] island fades its [GlassPill] through a [GlassReveal], so the
/// blur fades in with the fill instead of snapping on at the end; anything
/// else fades as a whole.
class SegmentedEntrance extends StatefulWidget {
const SegmentedEntrance({
super.key,
required this.child,
this.delay = Duration.zero,
this.play = true,
this.glass = true,
});
final Widget child;
final Duration delay;
final bool play;
final bool glass;
@override
State<SegmentedEntrance> createState() => _SegmentedEntranceState();
}
class _SegmentedEntranceState extends State<SegmentedEntrance>
with SingleTickerProviderStateMixin {
AnimationController? _controller;
Animation<double> _pop = kAlwaysCompleteAnimation;
Animation<double> _fade = kAlwaysCompleteAnimation;
bool _decided = false;
@override
void didChangeDependencies() {
super.didChangeDependencies();
// Decided once, on the first build: later dependency changes (a theme,
// a text scale) never replay it.
if (_decided) return;
_decided = true;
final window = Motion.of(context, Motion.barEntranceDuration);
if (!widget.play || window == Duration.zero) return;
final total = (widget.delay + window).inMicroseconds;
final begin = widget.delay.inMicroseconds / total;
final faded =
(widget.delay.inMicroseconds +
window.inMicroseconds * Motion.barEntranceOpacityPortion) /
total;
final controller = AnimationController(
vsync: this,
duration: widget.delay + window,
);
_controller = controller;
_pop = CurvedAnimation(
parent: controller,
curve: Interval(begin, 1, curve: Motion.barEntranceCurve),
);
_fade = CurvedAnimation(
parent: controller,
curve: Interval(begin, faded, curve: Curves.easeOut),
);
controller.forward();
}
@override
void dispose() {
if (_pop case final CurvedAnimation curved) curved.dispose();
if (_fade case final CurvedAnimation curved) curved.dispose();
_controller?.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final child = widget.glass
? GlassReveal(opacity: _fade, child: widget.child)
: FadeTransition(
opacity: _fade,
// Controls stay announced (and findable) while they fade in.
alwaysIncludeSemantics: true,
child: widget.child,
);
return AnimatedBuilder(
animation: _pop,
child: child,
builder: (context, child) => Transform.scale(
scale:
Motion.barEntranceScaleBegin +
(1 - Motion.barEntranceScaleBegin) * _pop.value,
child: child,
),
);
}
}
/// Press feedback for a control of a [SegmentedBar]: while a pointer is down
/// on [child] it sinks to [Motion.barPressScale] under a tint clipped to a
+14 -21
View File
@@ -19,21 +19,30 @@ abstract final class Motion {
/// The point at which the incoming tab begins to appear.
static const double tabFadeThroughIncomingAt = 0.35;
/// Duration of each tab's entrance pop.
// The entrance pop below is shared by the floating tab buttons and every
// piece of the top bar (Back, the title, the actions pill and each action
// in it); see `PopEntrance`.
/// Duration of each item's entrance pop.
static const Duration tabEntranceDuration = Duration(milliseconds: 260);
/// Delay between neighbouring tabs entering as one group.
/// Delay between neighbouring items entering as one group (tabs, or the
/// top bar's pieces from the leading edge).
static const Duration tabEntranceStagger = Duration(milliseconds: 70);
/// The scale at which a tab starts its entrance pop.
/// The scale at which an item starts its entrance pop.
static const double tabEntranceScaleBegin = 0.6;
/// The upward travel distance of a tab's entrance pop, in logical pixels.
/// The upward travel distance of an item's entrance pop, in logical
/// pixels.
static const double tabEntranceSlideDistance = 6;
/// The fraction of a tab's entrance spent fading in.
/// The fraction of an item's entrance spent fading in.
static const double tabEntranceOpacityPortion = 0.6;
/// The gentle overshoot of an item's entrance pop.
static const Curve tabEntranceCurve = Curves.easeOutBack;
/// How long a tab button's selection tint takes to cross-fade.
static const Duration tabSelectDuration = Duration(milliseconds: 220);
@@ -48,22 +57,6 @@ abstract final class Motion {
/// neighbours keep their gaps to it.
static const double tabSelectedScale = 1.2;
/// Duration of each top-bar island's entrance pop (Back, title, actions).
static const Duration barEntranceDuration = Duration(milliseconds: 240);
/// Delay between neighbouring top-bar islands entering together, from the
/// leading edge.
static const Duration barEntranceStagger = Duration(milliseconds: 40);
/// The scale at which a top-bar island starts its entrance.
static const double barEntranceScaleBegin = 0.85;
/// The fraction of an island's entrance spent fading in.
static const double barEntranceOpacityPortion = 0.6;
/// The gentle overshoot of an island's entrance.
static const Curve barEntranceCurve = Curves.easeOutBack;
/// How long a pressed top-bar control takes to sink.
static const Duration barPressDuration = Duration(milliseconds: 90);