feat(app): short motion for collapsibles, badges, new runs and the action bar; none under reduced motion
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import '../../../ui/motion/motion.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
@@ -128,6 +129,14 @@ class RunsList extends StatelessWidget {
|
|||||||
entries.add((label: group.label, run: null));
|
entries.add((label: group.label, run: null));
|
||||||
entries.addAll(group.runs.map((run) => (label: null, run: run)));
|
entries.addAll(group.runs.map((run) => (label: null, run: run)));
|
||||||
}
|
}
|
||||||
|
// Runs that start while the list is open enter with a short fade.
|
||||||
|
return ArrivalScope(
|
||||||
|
ids: [for (final run in controller.visibleRuns) '${run['id']}'],
|
||||||
|
child: _entriesList(entries),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _entriesList(List<({String? label, JsonMap? run})> entries) {
|
||||||
return ListView.builder(
|
return ListView.builder(
|
||||||
itemCount: entries.length,
|
itemCount: entries.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
@@ -141,7 +150,10 @@ class RunsList extends StatelessWidget {
|
|||||||
child: Semantics(header: true, child: Text(label, style: style)),
|
child: Semantics(header: true, child: Text(label, style: style)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return _runTile(context, entry.run!);
|
return Arrival(
|
||||||
|
id: '${entry.run!['id']}',
|
||||||
|
child: _runTile(context, entry.run!),
|
||||||
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import '../ui/motion/motion.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
@@ -145,9 +146,12 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
|||||||
automaticallyImplyLeading: false,
|
automaticallyImplyLeading: false,
|
||||||
middle: Text(spec?.title ?? details.label),
|
middle: Text(spec?.title ?? details.label),
|
||||||
trailing: spec != null && spec.actions.isNotEmpty
|
trailing: spec != null && spec.actions.isNotEmpty
|
||||||
? Row(
|
? MotionSwitcher(
|
||||||
mainAxisSize: MainAxisSize.min,
|
child: Row(
|
||||||
children: spec.actions,
|
key: ObjectKey(_bar.ownerFor(_selected)),
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: spec.actions,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
: widget.onSearch == null
|
: widget.onSearch == null
|
||||||
? null
|
? null
|
||||||
@@ -209,7 +213,15 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
|||||||
),
|
),
|
||||||
title: Text(spec?.title ?? details.label),
|
title: Text(spec?.title ?? details.label),
|
||||||
actions: [
|
actions: [
|
||||||
...?spec?.actions,
|
if (spec != null && spec.actions.isNotEmpty)
|
||||||
|
// A screen taking the bar over cross-fades its actions in.
|
||||||
|
MotionSwitcher(
|
||||||
|
child: Row(
|
||||||
|
key: ObjectKey(_bar.ownerFor(_selected)),
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: spec.actions,
|
||||||
|
),
|
||||||
|
),
|
||||||
if (widget.onSearch != null && (spec?.actions.isEmpty ?? true))
|
if (widget.onSearch != null && (spec?.actions.isEmpty ?? true))
|
||||||
IconButton(
|
IconButton(
|
||||||
key: const ValueKey('shell.search'),
|
key: const ValueKey('shell.search'),
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import 'package:flutter/cupertino.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import '../features/attention/domain/attention_models.dart';
|
import '../features/attention/domain/attention_models.dart';
|
||||||
|
import '../ui/motion/motion.dart';
|
||||||
|
|
||||||
/// Mirrors the Runs-heading bell count onto the Runs destination icon.
|
/// Mirrors the Runs-heading bell count onto the Runs destination icon.
|
||||||
///
|
///
|
||||||
@@ -28,7 +29,16 @@ class AttentionDestinationIcon extends StatelessWidget {
|
|||||||
final visible = count > 0;
|
final visible = count > 0;
|
||||||
final Widget icon = cupertino
|
final Widget icon = cupertino
|
||||||
? _CupertinoCountOverlay(count: count, visible: visible, child: child)
|
? _CupertinoCountOverlay(count: count, visible: visible, child: child)
|
||||||
: Badge(label: Text('$count'), isLabelVisible: visible, child: child);
|
: Badge(
|
||||||
|
label: visible
|
||||||
|
? MotionSwitcher(
|
||||||
|
scale: true,
|
||||||
|
child: Text('$count', key: ValueKey(count)),
|
||||||
|
)
|
||||||
|
: null,
|
||||||
|
isLabelVisible: visible,
|
||||||
|
child: child,
|
||||||
|
);
|
||||||
if (!visible) return icon;
|
if (!visible) return icon;
|
||||||
// The number alone would read as a stray "3"; the item carries the bell's
|
// The number alone would read as a stray "3"; the item carries the bell's
|
||||||
// full label instead.
|
// full label instead.
|
||||||
@@ -72,7 +82,10 @@ class _CupertinoCountOverlay extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 1),
|
padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 1),
|
||||||
child: Text('$count', style: style),
|
child: MotionSwitcher(
|
||||||
|
scale: true,
|
||||||
|
child: Text('$count', key: ValueKey(count), style: style),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -101,36 +114,37 @@ class ActivityBadge extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
if (count <= 0) return child;
|
final visible = count > 0;
|
||||||
final color = cupertino
|
final color = cupertino
|
||||||
? CupertinoColors.systemBlue.resolveFrom(context)
|
? CupertinoColors.systemBlue.resolveFrom(context)
|
||||||
: Theme.of(context).colorScheme.primary;
|
: Theme.of(context).colorScheme.primary;
|
||||||
final text = cupertino
|
final text = cupertino
|
||||||
? CupertinoColors.white
|
? CupertinoColors.white
|
||||||
: Theme.of(context).colorScheme.onPrimary;
|
: Theme.of(context).colorScheme.onPrimary;
|
||||||
return Semantics(
|
final stack = Stack(
|
||||||
label: '$count $label',
|
clipBehavior: Clip.none,
|
||||||
child: ExcludeSemantics(
|
children: [
|
||||||
child: Stack(
|
child,
|
||||||
clipBehavior: Clip.none,
|
PositionedDirectional(
|
||||||
children: [
|
top: bottom ? null : -6,
|
||||||
child,
|
bottom: bottom ? -6 : null,
|
||||||
PositionedDirectional(
|
end: -10,
|
||||||
top: bottom ? null : -6,
|
child: AnimatedScale(
|
||||||
bottom: bottom ? -6 : null,
|
scale: visible ? 1 : 0,
|
||||||
end: -10,
|
duration: Motion.of(context, Motion.quick),
|
||||||
child: DecoratedBox(
|
curve: Motion.curve,
|
||||||
decoration: ShapeDecoration(
|
child: DecoratedBox(
|
||||||
color: color,
|
decoration: ShapeDecoration(
|
||||||
shape: const StadiumBorder(),
|
color: color,
|
||||||
),
|
shape: const StadiumBorder(),
|
||||||
child: Padding(
|
),
|
||||||
padding: const EdgeInsets.symmetric(
|
child: Padding(
|
||||||
horizontal: 5,
|
padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 1),
|
||||||
vertical: 1,
|
child: MotionSwitcher(
|
||||||
),
|
scale: true,
|
||||||
child: Text(
|
child: Text(
|
||||||
'$count',
|
visible ? '$count' : '',
|
||||||
|
key: ValueKey(count),
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: text,
|
color: text,
|
||||||
fontSize: 10,
|
fontSize: 10,
|
||||||
@@ -140,9 +154,14 @@ class ActivityBadge extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
|
);
|
||||||
|
if (!visible) return stack;
|
||||||
|
return Semantics(
|
||||||
|
label: '$count $label',
|
||||||
|
child: ExcludeSemantics(child: stack),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,10 @@ class ShellBarRegistry extends ChangeNotifier {
|
|||||||
|
|
||||||
ShellBarSpec? specFor(AppDestination destination) => _specs[destination]?.$2;
|
ShellBarSpec? specFor(AppDestination destination) => _specs[destination]?.$2;
|
||||||
|
|
||||||
|
/// The screen that published [destination]'s bar; it changes when another
|
||||||
|
/// screen takes the bar over.
|
||||||
|
Object? ownerFor(AppDestination destination) => _specs[destination]?.$1;
|
||||||
|
|
||||||
void _set(AppDestination destination, Object owner, ShellBarSpec spec) {
|
void _set(AppDestination destination, Object owner, ShellBarSpec spec) {
|
||||||
// A screen's update can land after the shell itself has gone.
|
// A screen's update can land after the shell itself has gone.
|
||||||
if (_disposed) return;
|
if (_disposed) return;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import 'package:flutter/cupertino.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import '../adaptive/host.dart';
|
import '../adaptive/host.dart';
|
||||||
|
import '../motion/motion.dart';
|
||||||
|
|
||||||
/// A collapsible section for a [CustomScrollView]: its title stays pinned at
|
/// A collapsible section for a [CustomScrollView]: its title stays pinned at
|
||||||
/// the top while its content scrolls under it, so it can always be closed
|
/// the top while its content scrolls under it, so it can always be closed
|
||||||
@@ -50,7 +51,17 @@ class StickySection extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (open) SliverToBoxAdapter(child: body),
|
// The content grows and shrinks under the pinned title.
|
||||||
|
SliverToBoxAdapter(
|
||||||
|
child: ClipRect(
|
||||||
|
child: AnimatedSize(
|
||||||
|
duration: Motion.of(context, Motion.standard),
|
||||||
|
curve: Motion.curve,
|
||||||
|
alignment: Alignment.topCenter,
|
||||||
|
child: open ? body : const SizedBox(width: double.infinity),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -118,15 +129,16 @@ class StickySectionTitle extends StatelessWidget {
|
|||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Icon(
|
AnimatedRotation(
|
||||||
open
|
turns: open ? 0.5 : 0,
|
||||||
? (cupertino
|
duration: Motion.of(context, Motion.standard),
|
||||||
? CupertinoIcons.chevron_up
|
curve: Motion.curve,
|
||||||
: Icons.expand_less)
|
child: Icon(
|
||||||
: (cupertino
|
cupertino
|
||||||
? CupertinoIcons.chevron_down
|
? CupertinoIcons.chevron_down
|
||||||
: Icons.expand_more),
|
: Icons.expand_more,
|
||||||
color: muted,
|
color: muted,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -0,0 +1,167 @@
|
|||||||
|
import 'package:flutter/widgets.dart';
|
||||||
|
|
||||||
|
/// Short, quiet motion shared by the app: opening and closing sections,
|
||||||
|
/// counts and statuses changing, live items arriving. Every duration drops
|
||||||
|
/// to zero when the system asks for reduced motion.
|
||||||
|
abstract final class Motion {
|
||||||
|
/// A count, an icon or a status swapping in place.
|
||||||
|
static const Duration quick = Duration(milliseconds: 150);
|
||||||
|
|
||||||
|
/// A section opening or closing, a bar changing its actions.
|
||||||
|
static const Duration standard = Duration(milliseconds: 200);
|
||||||
|
|
||||||
|
static const Curve curve = Curves.easeOutCubic;
|
||||||
|
|
||||||
|
/// [duration], or zero under the system's reduce-motion setting.
|
||||||
|
static Duration of(BuildContext context, Duration duration) =>
|
||||||
|
MediaQuery.maybeDisableAnimationsOf(context) ?? false
|
||||||
|
? Duration.zero
|
||||||
|
: duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Swaps [child] with a short cross-fade whenever its key changes.
|
||||||
|
class MotionSwitcher extends StatelessWidget {
|
||||||
|
const MotionSwitcher({
|
||||||
|
super.key,
|
||||||
|
required this.child,
|
||||||
|
this.duration = Motion.quick,
|
||||||
|
this.scale = false,
|
||||||
|
});
|
||||||
|
|
||||||
|
final Widget child;
|
||||||
|
final Duration duration;
|
||||||
|
|
||||||
|
/// Also grows the incoming child from 80%: for badges and pills.
|
||||||
|
final bool scale;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) => AnimatedSwitcher(
|
||||||
|
duration: Motion.of(context, duration),
|
||||||
|
switchInCurve: Motion.curve,
|
||||||
|
switchOutCurve: Motion.curve,
|
||||||
|
transitionBuilder: (child, animation) {
|
||||||
|
final faded = FadeTransition(opacity: animation, child: child);
|
||||||
|
if (!scale) return faded;
|
||||||
|
return ScaleTransition(
|
||||||
|
scale: Tween<double>(begin: 0.8, end: 1).animate(animation),
|
||||||
|
child: faded,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
child: child,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Names the items of a live list, so items that arrive after the first load
|
||||||
|
/// can enter with a short fade and slide while the first load and items
|
||||||
|
/// scrolled into view appear at once.
|
||||||
|
class ArrivalScope extends StatefulWidget {
|
||||||
|
const ArrivalScope({super.key, required this.ids, required this.child});
|
||||||
|
|
||||||
|
/// Every item currently in the list, built or not.
|
||||||
|
final Iterable<Object> ids;
|
||||||
|
final Widget child;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<ArrivalScope> createState() => _ArrivalScopeState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ArrivalScopeState extends State<ArrivalScope> {
|
||||||
|
final Set<Object> _known = {};
|
||||||
|
final Set<Object> _fresh = {};
|
||||||
|
bool _primed = false;
|
||||||
|
|
||||||
|
void _absorb() {
|
||||||
|
final ids = widget.ids.toList();
|
||||||
|
if (!_primed) {
|
||||||
|
// The first non-empty list is the starting point, not an arrival.
|
||||||
|
if (ids.isEmpty) return;
|
||||||
|
_known.addAll(ids);
|
||||||
|
_primed = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (final id in ids) {
|
||||||
|
if (_known.add(id)) _fresh.add(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_absorb();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didUpdateWidget(ArrivalScope oldWidget) {
|
||||||
|
super.didUpdateWidget(oldWidget);
|
||||||
|
_absorb();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// True once for an item that arrived after the first load.
|
||||||
|
bool _claim(Object id) => _fresh.remove(id);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) =>
|
||||||
|
_ArrivalData(state: this, child: widget.child);
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ArrivalData extends InheritedWidget {
|
||||||
|
const _ArrivalData({required this.state, required super.child});
|
||||||
|
|
||||||
|
final _ArrivalScopeState state;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool updateShouldNotify(_ArrivalData oldWidget) => false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// One item of an [ArrivalScope]: fades and slides in when it is new.
|
||||||
|
class Arrival extends StatefulWidget {
|
||||||
|
const Arrival({super.key, required this.id, required this.child});
|
||||||
|
|
||||||
|
final Object id;
|
||||||
|
final Widget child;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<Arrival> createState() => _ArrivalState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ArrivalState extends State<Arrival> with SingleTickerProviderStateMixin {
|
||||||
|
AnimationController? _controller;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didChangeDependencies() {
|
||||||
|
super.didChangeDependencies();
|
||||||
|
if (_controller != null) return;
|
||||||
|
final scope = context.getInheritedWidgetOfExactType<_ArrivalData>()?.state;
|
||||||
|
final duration = Motion.of(context, Motion.standard);
|
||||||
|
if (scope == null ||
|
||||||
|
duration == Duration.zero ||
|
||||||
|
!scope._claim(widget.id)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_controller = AnimationController(vsync: this, duration: duration)
|
||||||
|
..forward();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_controller?.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final controller = _controller;
|
||||||
|
if (controller == null) return widget.child;
|
||||||
|
final curved = CurvedAnimation(parent: controller, curve: Motion.curve);
|
||||||
|
return FadeTransition(
|
||||||
|
opacity: curved,
|
||||||
|
child: SlideTransition(
|
||||||
|
position: Tween<Offset>(
|
||||||
|
begin: const Offset(0, 0.15),
|
||||||
|
end: Offset.zero,
|
||||||
|
).animate(curved),
|
||||||
|
child: widget.child,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -56,7 +56,10 @@ void main() {
|
|||||||
expect(badge, findsOneWidget);
|
expect(badge, findsOneWidget);
|
||||||
expect(tester.widget<Badge>(badge).isLabelVisible, isFalse);
|
expect(tester.widget<Badge>(badge).isLabelVisible, isFalse);
|
||||||
expect(
|
expect(
|
||||||
find.descendant(of: badge, matching: find.byType(Text)),
|
find.descendant(
|
||||||
|
of: badge,
|
||||||
|
matching: find.textContaining(RegExp(r'\d')),
|
||||||
|
),
|
||||||
findsNothing,
|
findsNothing,
|
||||||
);
|
);
|
||||||
expect(find.bySemanticsLabel(anyAttention), findsNothing);
|
expect(find.bySemanticsLabel(anyAttention), findsNothing);
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ void main() {
|
|||||||
expect(
|
expect(
|
||||||
find.descendant(
|
find.descendant(
|
||||||
of: find.byKey(const ValueKey('shell.badge.chat.unread')),
|
of: find.byKey(const ValueKey('shell.badge.chat.unread')),
|
||||||
matching: find.byType(Text),
|
matching: find.textContaining(RegExp(r'\d')),
|
||||||
),
|
),
|
||||||
findsNothing,
|
findsNothing,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:pipelines_app/ui/motion/motion.dart';
|
||||||
|
|
||||||
|
Widget _list(List<String> ids, {bool reduce = false}) => Directionality(
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
child: MediaQuery(
|
||||||
|
data: MediaQueryData(disableAnimations: reduce),
|
||||||
|
child: ArrivalScope(
|
||||||
|
ids: ids,
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
for (final id in ids)
|
||||||
|
Arrival(key: ValueKey(id), id: id, child: Text(id)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
Finder _fadeOf(String id) =>
|
||||||
|
find.ancestor(of: find.text(id), matching: find.byType(FadeTransition));
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
testWidgets('only items after the first load fade in', (tester) async {
|
||||||
|
await tester.pumpWidget(_list(['a', 'b']));
|
||||||
|
expect(_fadeOf('a'), findsNothing);
|
||||||
|
|
||||||
|
await tester.pumpWidget(_list(['c', 'a', 'b']));
|
||||||
|
expect(_fadeOf('c'), findsOneWidget);
|
||||||
|
expect(_fadeOf('a'), findsNothing);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('reduced motion shows arrivals at once', (tester) async {
|
||||||
|
await tester.pumpWidget(_list(['a'], reduce: true));
|
||||||
|
await tester.pumpWidget(_list(['b', 'a'], reduce: true));
|
||||||
|
expect(_fadeOf('b'), findsNothing);
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user