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:
@@ -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),
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -20,7 +20,9 @@ above the shell row).
|
||||
the gaps over the content.
|
||||
- Entrance: each whole button pops in (0.6 -> 1, ease-out-back, 70 ms
|
||||
stagger), its glass fading through `GlassReveal`; only when the bar first
|
||||
builds or its tab set changes.
|
||||
builds or its tab set changes. The pop (`PopTransition`, `popWindow` in
|
||||
`pop_entrance.dart`) is shared with every piece of the top bar
|
||||
(`topbar-island-motion.md`).
|
||||
- Press: `SegmentedPress`, as in the top bar; Material keeps its circular ink.
|
||||
- Semantics: the row is a `SemanticsRole.tabBar`; each button a merged
|
||||
`SemanticsRole.tab` button with its selected state, named by its label, and
|
||||
|
||||
@@ -1,15 +1,34 @@
|
||||
# Top bar island motion and press feedback
|
||||
|
||||
- Entrance: each island of `SegmentedBar` (Back, title or field pill, actions
|
||||
pill, and each action inside the pill) is a `SegmentedEntrance`
|
||||
(`lib/ui/adaptive/segmented_bar_motion.dart`). It scales in from 0.85 with
|
||||
`easeOutBack` over 240 ms and fades in. On the bar's first frame the islands
|
||||
are staggered 40 ms apart from the leading edge. An island added later pops
|
||||
in straight away. Actions that arrive together with their pill don't pop a
|
||||
second time. The islands are keyed by role, and actions by their key (or
|
||||
their type and position), so a rebuild, a new title or a shell tab switch
|
||||
keeps the pills that are already there. Under reduced motion nothing
|
||||
animates.
|
||||
- Entrance: the top bar pops in exactly like the floating tab buttons. Both
|
||||
use `lib/ui/adaptive/pop_entrance.dart` (`PopTransition`, `popWindow`; the
|
||||
self-driven `PopEntrance` for the bar) and the `Motion.tabEntrance*`
|
||||
constants: from 0.6, rising 6 px, `easeOutBack` over 260 ms, fading in
|
||||
over the first 60%, 70 ms apart. The old 0.85/240 ms/40 ms bar constants
|
||||
and `SegmentedEntrance` are gone.
|
||||
- Each piece pops on its own: Back, the title or field pill, the actions
|
||||
pill, and each action in it. `SegmentedEntrancePlanner`
|
||||
(`segmented_bar_entrance.dart`) times them. On the bar's first frame they
|
||||
go in turn from the leading edge: Back, title, pill, then each action left
|
||||
to right. A lone action is the whole pill, so it pops once, with the pill.
|
||||
A pill that turns up later pops at once and its actions follow it in turn.
|
||||
An action added to a pill that is already there pops alone. Pieces are keyed
|
||||
by role and actions by identity (their key, or their type and position,
|
||||
within `SegmentedBar.actionsKey`), so a rebuild, a new title or scrolling
|
||||
never replays them. Under reduced motion nothing animates.
|
||||
- Shell tab switch: the shell passes the open screen's owner as
|
||||
`actionsKey` and its published actions one by one. It used to wrap them in
|
||||
one cross-fading `Row`, which made them a single action. On a switch Back
|
||||
and the title stay put, and the new screen's actions pop in turn. A screen
|
||||
republishing its bar keeps them.
|
||||
- Actions after the first keep their natural width, capped at an even share
|
||||
of the pill. That keeps the chat's mode beside the model, and icons in a
|
||||
narrow split pane squeeze instead of overflowing.
|
||||
- Rerouted bars: the chat thread's model and permission mode used to be one
|
||||
`LayoutBuilder` `Row` action and are now two actions. The folder picker
|
||||
used a stock `AppBar` / `CupertinoNavigationBar` and is now a
|
||||
`SegmentedBar` (round Back that climbs a folder, title, Cancel). Every other
|
||||
screen already built its bar through `SegmentedBar` with separate actions.
|
||||
- Glass fades through `GlassReveal` (`glass_pill.dart`): the fill, the hairline,
|
||||
the blur sigma and the content fade together. An opacity layer would hide
|
||||
the backdrop from `BackdropFilter.grouped` until the fade ended. Grouping is
|
||||
@@ -22,3 +41,6 @@
|
||||
when there are several. Native ink and Cupertino dimming still show.
|
||||
- Evidence: films at 560x900 in Material and Cupertino, light and dark, are in
|
||||
`/tmp/topbar-evidence/` (strips `strip-*.png`, zoomed presses `zoom-press*.png`).
|
||||
The shared pop is filmed in `/tmp/topbar-pop/` (`material/`, `cupertino/`:
|
||||
Pipelines <-> Runs, Search, run detail, Chat list and thread; `folder-*`:
|
||||
the folder picker; `strip-*.png` stack the bar of every frame).
|
||||
|
||||
@@ -138,7 +138,9 @@ void main() {
|
||||
// Content may still extend under the bars and the status bar.
|
||||
expect(tester.getTopLeft(find.byKey(const Key('list'))).dy, 0);
|
||||
expect(tester.getTopLeft(find.byKey(const Key('item-list'))).dy, 0);
|
||||
// At rest the first rows start below the bars.
|
||||
// At rest (the bars' pieces have popped in) the first rows start
|
||||
// below the bars.
|
||||
await tester.pump(const Duration(seconds: 1));
|
||||
final paneBottom = pillsOf(tester, paneBar).first.bottom;
|
||||
expect(
|
||||
tester.getTopLeft(find.text('item 0')).dy,
|
||||
|
||||
@@ -0,0 +1,223 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/ui/adaptive/pop_entrance.dart';
|
||||
import 'package:pipelines_app/ui/adaptive/segmented_bar.dart';
|
||||
import 'package:pipelines_app/ui/motion/motion.dart';
|
||||
|
||||
/// Every piece of the top bar (Back, the title, the actions pill and each
|
||||
/// action in it) pops in with the tab buttons' entrance, once.
|
||||
void main() {
|
||||
Widget page(
|
||||
bool cupertino, {
|
||||
String title = 'Runs',
|
||||
List<Widget> actions = const [],
|
||||
Object? actionsKey,
|
||||
bool reduced = false,
|
||||
}) {
|
||||
final bar = SegmentedBar(
|
||||
cupertino: cupertino,
|
||||
title: title,
|
||||
leading: SegmentedBackButton(
|
||||
key: const Key('back'),
|
||||
cupertino: cupertino,
|
||||
onPressed: () {},
|
||||
),
|
||||
actions: actions,
|
||||
actionsKey: actionsKey,
|
||||
);
|
||||
final Widget home = cupertino
|
||||
? CupertinoPageScaffold(
|
||||
navigationBar: bar,
|
||||
child: const SizedBox.expand(),
|
||||
)
|
||||
: Scaffold(
|
||||
extendBodyBehindAppBar: true,
|
||||
appBar: bar,
|
||||
body: const SizedBox.expand(),
|
||||
);
|
||||
final app = cupertino ? CupertinoApp(home: home) : MaterialApp(home: home);
|
||||
return MediaQuery(
|
||||
data: MediaQueryData(disableAnimations: reduced),
|
||||
child: app,
|
||||
);
|
||||
}
|
||||
|
||||
/// The entrance scale of the piece holding [of]: its pill's, or with
|
||||
/// [inner] its own inside the actions pill.
|
||||
double scaleOf(WidgetTester tester, Finder of, {bool inner = false}) {
|
||||
final entrances = find.ancestor(of: of, matching: find.byType(PopEntrance));
|
||||
final entrance = inner ? entrances.first : entrances.last;
|
||||
// The pop rises (a translation), then scales.
|
||||
final transform = tester.widget<Transform>(
|
||||
find.descendant(of: entrance, matching: find.byType(Transform)).at(1),
|
||||
);
|
||||
return transform.transform.storage[0];
|
||||
}
|
||||
|
||||
final back = find.byKey(const Key('back'));
|
||||
final title = find.text('Runs');
|
||||
const begin = Motion.tabEntranceScaleBegin;
|
||||
const step = Motion.tabEntranceStagger;
|
||||
|
||||
for (final cupertino in [false, true]) {
|
||||
final host = cupertino ? 'Cupertino' : 'Material';
|
||||
final icon = cupertino ? CupertinoIcons.refresh : Icons.refresh;
|
||||
Widget action(String key) =>
|
||||
IconButton(key: Key(key), icon: Icon(icon), onPressed: () {});
|
||||
final a = find.byKey(const Key('a'));
|
||||
final b = find.byKey(const Key('b'));
|
||||
|
||||
testWidgets('$host: each piece pops in turn, left to right, from 0.6', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
page(cupertino, actions: [action('a'), action('b')]),
|
||||
);
|
||||
expect(scaleOf(tester, back), begin);
|
||||
expect(scaleOf(tester, title), begin);
|
||||
expect(scaleOf(tester, a), begin, reason: 'the pill');
|
||||
expect(scaleOf(tester, a, inner: true), begin);
|
||||
expect(scaleOf(tester, b, inner: true), begin);
|
||||
// Back, the title, the pill, then each action: one stagger apart.
|
||||
await tester.pump(step * 2 + const Duration(milliseconds: 20));
|
||||
final backNow = scaleOf(tester, back);
|
||||
final titleNow = scaleOf(tester, title);
|
||||
final pillNow = scaleOf(tester, a);
|
||||
expect(backNow, greaterThan(titleNow), reason: 'Back leads');
|
||||
expect(titleNow, greaterThan(pillNow), reason: 'the title follows');
|
||||
expect(pillNow, greaterThan(begin), reason: 'the pill has started');
|
||||
expect(scaleOf(tester, a, inner: true), begin, reason: 'a waits');
|
||||
await tester.pump(step);
|
||||
expect(scaleOf(tester, a, inner: true), greaterThan(begin));
|
||||
expect(scaleOf(tester, b, inner: true), begin, reason: 'b waits for a');
|
||||
await tester.pump(step);
|
||||
expect(scaleOf(tester, b, inner: true), greaterThan(begin));
|
||||
await tester.pumpAndSettle();
|
||||
for (final scale in [
|
||||
scaleOf(tester, back),
|
||||
scaleOf(tester, title),
|
||||
scaleOf(tester, a),
|
||||
scaleOf(tester, a, inner: true),
|
||||
scaleOf(tester, b, inner: true),
|
||||
]) {
|
||||
expect(scale, 1);
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('$host: a lone action pops as its pill, not twice', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(page(cupertino, actions: [action('a')]));
|
||||
expect(scaleOf(tester, a), begin);
|
||||
expect(scaleOf(tester, a, inner: true), 1);
|
||||
await tester.pump(step * 2 + const Duration(milliseconds: 40));
|
||||
expect(scaleOf(tester, a), greaterThan(begin));
|
||||
expect(scaleOf(tester, a, inner: true), 1);
|
||||
await tester.pumpAndSettle();
|
||||
expect(scaleOf(tester, a), 1);
|
||||
});
|
||||
|
||||
testWidgets('$host: a rebuild or new title does not replay it', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(page(cupertino, actions: [action('a')]));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.pumpWidget(
|
||||
page(cupertino, title: 'Other', actions: [action('a')]),
|
||||
);
|
||||
await tester.pump();
|
||||
expect(scaleOf(tester, back), 1);
|
||||
expect(scaleOf(tester, find.text('Other')), 1);
|
||||
expect(scaleOf(tester, a), 1);
|
||||
expect(scaleOf(tester, a, inner: true), 1);
|
||||
expect(tester.hasRunningAnimations, isFalse);
|
||||
});
|
||||
|
||||
testWidgets('$host: an action that becomes available pops in alone', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(page(cupertino, actions: [action('a')]));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.pumpWidget(
|
||||
page(cupertino, actions: [action('b'), action('a')]),
|
||||
);
|
||||
expect(scaleOf(tester, b, inner: true), begin);
|
||||
// The pill, the action already there and the rest stay put.
|
||||
expect(scaleOf(tester, a), 1);
|
||||
expect(scaleOf(tester, a, inner: true), 1);
|
||||
expect(scaleOf(tester, back), 1);
|
||||
expect(scaleOf(tester, title), 1);
|
||||
await tester.pump(Motion.tabEntranceDuration ~/ 2);
|
||||
expect(scaleOf(tester, b, inner: true), greaterThan(0.9));
|
||||
await tester.pumpAndSettle();
|
||||
expect(scaleOf(tester, b, inner: true), 1);
|
||||
});
|
||||
|
||||
testWidgets('$host: a tab switch keeps what stays, pops what is new', (
|
||||
tester,
|
||||
) async {
|
||||
final list = Object();
|
||||
await tester.pumpWidget(
|
||||
page(cupertino, actionsKey: list, actions: [action('a')]),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
// The same screen republishing its bar is not a new entrance.
|
||||
await tester.pumpWidget(
|
||||
page(cupertino, actionsKey: list, actions: [action('a')]),
|
||||
);
|
||||
await tester.pump();
|
||||
expect(tester.hasRunningAnimations, isFalse);
|
||||
// Another screen's actions are new, though keyed alike; Back, the
|
||||
// title and the pill stay.
|
||||
await tester.pumpWidget(
|
||||
page(
|
||||
cupertino,
|
||||
title: 'Chats',
|
||||
actionsKey: Object(),
|
||||
actions: [action('a'), action('b')],
|
||||
),
|
||||
);
|
||||
expect(scaleOf(tester, back), 1);
|
||||
expect(scaleOf(tester, find.text('Chats')), 1);
|
||||
expect(scaleOf(tester, a), 1, reason: 'the pill stays');
|
||||
expect(scaleOf(tester, a, inner: true), begin);
|
||||
expect(scaleOf(tester, b, inner: true), begin);
|
||||
await tester.pump(step);
|
||||
expect(scaleOf(tester, a, inner: true), greaterThan(begin));
|
||||
expect(scaleOf(tester, b, inner: true), begin);
|
||||
await tester.pumpAndSettle();
|
||||
expect(scaleOf(tester, b, inner: true), 1);
|
||||
});
|
||||
|
||||
testWidgets('$host: a pill arriving later pops, then its actions', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(page(cupertino));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.pumpWidget(
|
||||
page(cupertino, actions: [action('a'), action('b')]),
|
||||
);
|
||||
expect(scaleOf(tester, back), 1);
|
||||
await tester.pump(const Duration(milliseconds: 20));
|
||||
expect(scaleOf(tester, a), greaterThan(begin), reason: 'at once');
|
||||
expect(scaleOf(tester, a, inner: true), begin);
|
||||
await tester.pump(step);
|
||||
expect(scaleOf(tester, a, inner: true), greaterThan(begin));
|
||||
expect(scaleOf(tester, b, inner: true), begin);
|
||||
await tester.pumpAndSettle();
|
||||
});
|
||||
|
||||
testWidgets('$host: reduced motion shows the bar at once', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
page(cupertino, actions: [action('a'), action('b')], reduced: true),
|
||||
);
|
||||
expect(scaleOf(tester, back), 1);
|
||||
expect(scaleOf(tester, title), 1);
|
||||
expect(scaleOf(tester, a), 1);
|
||||
expect(scaleOf(tester, a, inner: true), 1);
|
||||
expect(scaleOf(tester, b, inner: true), 1);
|
||||
expect(tester.hasRunningAnimations, isFalse);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,8 @@ import 'package:pipelines_app/ui/adaptive/segmented_bar_motion.dart';
|
||||
import 'package:pipelines_app/ui/adaptive/segmented_bar_pieces.dart';
|
||||
import 'package:pipelines_app/ui/motion/motion.dart';
|
||||
|
||||
/// The top bar's islands pop in once, and its controls sink when pressed.
|
||||
/// The top bar's glass fades in with its blur, and its controls sink when
|
||||
/// pressed (its entrance is in segmented_bar_entrance_test.dart).
|
||||
void main() {
|
||||
Widget page(
|
||||
bool cupertino, {
|
||||
@@ -46,20 +47,6 @@ void main() {
|
||||
);
|
||||
}
|
||||
|
||||
/// The entrance scale of the island holding [of]: its pill's, or with
|
||||
/// [inner] its own inside the actions pill.
|
||||
double entranceScale(WidgetTester tester, Finder of, {bool inner = false}) {
|
||||
final entrances = find.ancestor(
|
||||
of: of,
|
||||
matching: find.byType(SegmentedEntrance),
|
||||
);
|
||||
final entrance = inner ? entrances.first : entrances.last;
|
||||
final transform = tester.widget<Transform>(
|
||||
find.descendant(of: entrance, matching: find.byType(Transform)).first,
|
||||
);
|
||||
return transform.transform.storage[0];
|
||||
}
|
||||
|
||||
/// The press scale of the control holding [of], or with [pill] of the
|
||||
/// pill holding it.
|
||||
double pressScale(WidgetTester tester, Finder of, {bool pill = false}) {
|
||||
@@ -93,77 +80,12 @@ void main() {
|
||||
Widget action(String key) =>
|
||||
IconButton(key: Key(key), icon: Icon(icon), onPressed: () {});
|
||||
|
||||
testWidgets('$host: the islands pop in left to right on first show', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(page(cupertino, actions: [action('a')]));
|
||||
final a = find.byKey(const Key('a'));
|
||||
expect(entranceScale(tester, back), Motion.barEntranceScaleBegin);
|
||||
await tester.pump(const Duration(milliseconds: 120));
|
||||
final b = entranceScale(tester, back);
|
||||
final t = entranceScale(tester, title);
|
||||
final r = entranceScale(tester, a);
|
||||
expect(b, greaterThan(t), reason: 'Back leads the title');
|
||||
expect(t, greaterThan(r), reason: 'the title leads the actions');
|
||||
expect(r, greaterThan(Motion.barEntranceScaleBegin));
|
||||
await tester.pumpAndSettle();
|
||||
expect(entranceScale(tester, back), 1);
|
||||
expect(entranceScale(tester, title), 1);
|
||||
expect(entranceScale(tester, a), 1);
|
||||
});
|
||||
|
||||
testWidgets('$host: a rebuild or new title does not replay it', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(page(cupertino, actions: [action('a')]));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.pumpWidget(
|
||||
page(cupertino, title: 'Other', actions: [action('a')]),
|
||||
);
|
||||
await tester.pump();
|
||||
expect(entranceScale(tester, back), 1);
|
||||
expect(entranceScale(tester, find.text('Other')), 1);
|
||||
expect(entranceScale(tester, find.byKey(const Key('a'))), 1);
|
||||
expect(tester.hasRunningAnimations, isFalse);
|
||||
});
|
||||
|
||||
testWidgets('$host: an action that becomes available pops in alone', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(page(cupertino, actions: [action('a')]));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.pumpWidget(
|
||||
page(cupertino, actions: [action('b'), action('a')]),
|
||||
);
|
||||
final newcomer = find.byKey(const Key('b'));
|
||||
expect(
|
||||
entranceScale(tester, newcomer, inner: true),
|
||||
Motion.barEntranceScaleBegin,
|
||||
);
|
||||
// The pill and the action already there stay put.
|
||||
expect(entranceScale(tester, find.byKey(const Key('a'))), 1);
|
||||
expect(entranceScale(tester, find.byKey(const Key('a')), inner: true), 1);
|
||||
expect(entranceScale(tester, back), 1);
|
||||
await tester.pump(Motion.barEntranceDuration ~/ 2);
|
||||
expect(entranceScale(tester, newcomer, inner: true), greaterThan(0.9));
|
||||
await tester.pumpAndSettle();
|
||||
expect(entranceScale(tester, newcomer, inner: true), 1);
|
||||
});
|
||||
|
||||
testWidgets('$host: reduced motion shows the bar at once', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
page(cupertino, actions: [action('a')], reduced: true),
|
||||
);
|
||||
expect(entranceScale(tester, back), 1);
|
||||
expect(entranceScale(tester, title), 1);
|
||||
expect(tester.hasRunningAnimations, isFalse);
|
||||
});
|
||||
|
||||
testWidgets('$host: the glass fades in with its blur, not under a layer', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(page(cupertino));
|
||||
await tester.pump(const Duration(milliseconds: 40));
|
||||
// Back and the title are both still popping in.
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
final backdrops = tester.layers.whereType<BackdropFilterLayer>().toList();
|
||||
expect(backdrops, hasLength(2), reason: 'Back and the title');
|
||||
expect(backdrops.first.backdropKey, isNotNull, reason: 'still grouped');
|
||||
|
||||
Reference in New Issue
Block a user