Files
pipelines/app/lib/ui/adaptive/segmented_bar_entrance.dart
T
alan 05798a56c8 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.
2026-11-03 00:30:44 +00:00

94 lines
3.1 KiB
Dart

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,
);
}
}