fix(motion): replace the tutorial and lyrics card bounce curves with springs

The tutorial page dots, demo frame and page icon, and the lyrics card
background swatches, line rows and line checks used easeOutBack. They now
run on the AppMotion springs: Material's expressive spatial springs, which
overshoot by themselves, and Mornye's springs without a bounce. The
tutorial pages turn on the slow spatial spring, its tips rise through the
shared staggered reveal, and its fades use the effects springs. Reduced
motion is honoured where the tutorial ignored it: pages jump and the demo
frame resizes at once.
This commit is contained in:
zarzet committed 2026-11-17 12:57:37 +07:00
1 parent 48d84378a6
commit a72648254d
3 files changed
+209 -77

No files matched your search

+36 -15
View File
@@ -6,6 +6,7 @@ import 'package:material_3_expressive/material_3_expressive.dart'
show M3EShapeKind;
import 'package:share_plus/share_plus.dart' show ShareParams, SharePlus, XFile;
import 'package:mornye/l10n/l10n.dart';
import 'package:mornye/theme/app_motion.dart';
import 'package:mornye/theme/app_tokens.dart';
import 'package:mornye/theme/cover_palette.dart';
import 'package:mornye/utils/lyrics_parser.dart';
@@ -27,6 +28,9 @@ const lyricsShareCardSize = Size(360, 640);
typedef LyricsShareLine = ({String text, bool background});
/// Reduced motion: the pickers change at once.
const _still = AppMotionSpec(Duration.zero, Curves.linear);
/// Lines a card can quote: timed lines in order, or the plain text's lines.
List<LyricsShareLine> lyricsShareLines(ParsedLyrics lyrics) {
if (lyrics.lines.isNotEmpty) {
@@ -413,7 +417,13 @@ class _BackgroundPicker extends StatelessWidget {
colors: [Color(0xFFFFFFFF), Color(0xFFE8E4DC)],
),
};
final reduceMotion = MediaQuery.disableAnimationsOf(context);
// A small control: the fast spatial spring overshoots by itself in
// Material, Mornye settles without a bounce, reduced motion jumps.
final morph = AppMotion.spatialFast(
context,
_still,
mornye: MornyeMotion.fast,
);
return Container(
height: 64,
padding: const EdgeInsets.symmetric(horizontal: 6),
@@ -445,10 +455,8 @@ class _BackgroundPicker extends StatelessWidget {
// The chosen swatch morphs from a circle into a larger
// rounded square, the Expressive selection cue.
child: AnimatedContainer(
duration: reduceMotion
? Duration.zero
: const Duration(milliseconds: 260),
curve: Curves.easeOutBack,
duration: morph.duration,
curve: morph.curve,
width: option == value ? 42 : 32,
height: option == value ? 42 : 32,
clipBehavior: Clip.antiAlias,
@@ -511,10 +519,14 @@ class _SelectionCount extends StatelessWidget {
final theme = Theme.of(context);
final colors = theme.colorScheme;
final active = count > 0;
final tint = AppMotion.effectsFast(
context,
_still,
mornye: MornyeMotion.effectsFast,
);
return AnimatedContainer(
duration: MediaQuery.disableAnimationsOf(context)
? Duration.zero
: const Duration(milliseconds: 200),
duration: tint.duration,
curve: tint.curve,
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
decoration: ShapeDecoration(
color: active ? colors.primaryContainer : colors.surfaceContainerHigh,
@@ -561,9 +573,18 @@ class _LineChoice extends StatelessWidget {
top: first ? outer : inner,
bottom: last ? outer : inner,
);
final duration = MediaQuery.disableAnimationsOf(context)
? Duration.zero
: const Duration(milliseconds: 220);
// The row reshapes on the default spatial spring and its check on the
// fast one; reduced motion jumps.
final reshape = AppMotion.spatial(
context,
_still,
mornye: MornyeMotion.standard,
);
final check = AppMotion.spatialFast(
context,
_still,
mornye: MornyeMotion.fast,
);
return Padding(
padding: EdgeInsets.only(bottom: last ? 0 : 2),
child: MergeSemantics(
@@ -572,8 +593,8 @@ class _LineChoice extends StatelessWidget {
// The container clips its own ink, so the press highlight follows
// the corners while they animate.
child: AnimatedContainer(
duration: duration,
curve: Curves.easeOutCubic,
duration: reshape.duration,
curve: reshape.curve,
clipBehavior: Clip.antiAlias,
decoration: BoxDecoration(
color: selected
@@ -595,8 +616,8 @@ class _LineChoice extends StatelessWidget {
child: Row(
children: [
AnimatedContainer(
duration: duration,
curve: Curves.easeOutBack,
duration: check.duration,
curve: check.curve,
width: 24,
height: 24,
decoration: BoxDecoration(
+109 -62
View File
@@ -4,9 +4,11 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:mornye/providers/settings_provider.dart';
import 'package:mornye/l10n/l10n.dart';
import 'package:mornye/theme/app_motion.dart';
import 'package:mornye/theme/app_tokens.dart';
import 'package:mornye/utils/adaptive_layout.dart';
import 'package:mornye/utils/desktop_platform.dart';
import 'package:mornye/widgets/animation_utils.dart';
import 'package:mornye/widgets/scroll_edge_fade.dart';
import 'package:mornye/widgets/app_icon_button.dart';
import 'package:mornye/widgets/app_loading_indicator.dart';
@@ -35,22 +37,34 @@ class _TutorialScreenState extends ConsumerState<TutorialScreen> {
void _nextPage() {
if (_currentPage < _totalPages - 1) {
_pageController.nextPage(
duration: const Duration(milliseconds: 600),
curve: Curves.easeOutQuart,
);
_turnToPage(_currentPage + 1);
} else {
_completeTutorial();
}
}
void _prevPage() {
_pageController.previousPage(
duration: const Duration(milliseconds: 600),
curve: Curves.easeOutQuart,
void _prevPage() => _turnToPage(_currentPage - 1);
/// A page moves on the slow spatial spring, which stops at the page
/// without overshoot; reduced motion shows the page at once.
void _turnToPage(int page) {
if (MediaQuery.disableAnimationsOf(context)) {
_pageController.jumpToPage(page);
return;
}
final motion = AppMotion.spatialSlow(context, _pageMotion);
_pageController.animateToPage(
page,
duration: motion.duration,
curve: motion.curve,
);
}
static const _pageMotion = AppMotionSpec(
Duration(milliseconds: 600),
Curves.easeOutQuart,
);
void _completeTutorial() {
ref.read(settingsProvider.notifier).setTutorialComplete();
context.go('/');
@@ -75,6 +89,15 @@ class _TutorialScreenState extends ConsumerState<TutorialScreen> {
final activeIndicatorWidth = 32 * scale;
final bottomGap = (32 * scale) + ((textScale - 1) * 8);
final actionButtonHeight = (56 * scale) + ((textScale - 1) * 6);
final backFade = AppMotion.effects(
context,
const AppMotionSpec(Duration(milliseconds: 300), Curves.linear),
);
final indicatorMotion = AppMotion.spatialFast(
context,
const AppMotionSpec(Duration.zero, Curves.linear),
mornye: MornyeMotion.fast,
);
final scaffold = Scaffold(
backgroundColor: colorScheme.surface,
@@ -91,7 +114,8 @@ class _TutorialScreenState extends ConsumerState<TutorialScreen> {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
AnimatedOpacity(
duration: const Duration(milliseconds: 300),
duration: backFade.duration,
curve: backFade.curve,
opacity: _currentPage > 0 ? 1.0 : 0.0,
child: AppIconButton.filledTonal(
onPressed: _currentPage > 0 ? _prevPage : null,
@@ -221,9 +245,11 @@ class _TutorialScreenState extends ConsumerState<TutorialScreen> {
mainAxisAlignment: MainAxisAlignment.center,
children: List.generate(_totalPages, (index) {
final isActive = _currentPage == index;
// The fast spatial spring overshoots by itself in
// Material; Mornye settles without a bounce.
return AnimatedContainer(
duration: const Duration(milliseconds: 300),
curve: Curves.easeOutBack,
duration: indicatorMotion.duration,
curve: indicatorMotion.curve,
margin: EdgeInsets.symmetric(horizontal: 4 * scale),
height: pageIndicatorHeight,
width: isActive
@@ -302,52 +328,40 @@ class _TutorialScreenState extends ConsumerState<TutorialScreen> {
List<(IconData, String)> features,
) {
final colorScheme = Theme.of(context).colorScheme;
// The tips rise one after another on the spatial spring and fade in on
// the effects spring; reduced motion shows them at once.
return Column(
children: features.asMap().entries.map((entry) {
final index = entry.key;
final feature = entry.value;
return TweenAnimationBuilder<double>(
tween: Tween(begin: 0, end: 1),
duration: Duration(milliseconds: 600 + (index * 200)),
curve: Curves.easeOutQuart,
builder: (context, value, child) {
return Transform.translate(
offset: Offset(0, 20 * (1 - value)),
child: Opacity(
opacity: value,
child: Padding(
padding: const EdgeInsets.only(bottom: 16),
child: Row(
children: [
Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: colorScheme.surfaceContainerHighest,
borderRadius: BorderRadius.circular(16),
),
child: Icon(
feature.$1,
size: 24,
color: colorScheme.primary,
),
),
const SizedBox(width: 20),
Expanded(
child: Text(
feature.$2,
style: Theme.of(context).textTheme.bodyLarge
?.copyWith(
color: colorScheme.onSurface,
fontWeight: FontWeight.w500,
),
),
),
],
return StaggeredListItem(
index: index,
staggerDelay: const Duration(milliseconds: 100),
child: Padding(
padding: const EdgeInsets.only(bottom: 16),
child: Row(
children: [
Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: colorScheme.surfaceContainerHighest,
borderRadius: BorderRadius.circular(16),
),
child: Icon(feature.$1, size: 24, color: colorScheme.primary),
),
const SizedBox(width: 20),
Expanded(
child: Text(
feature.$2,
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
color: colorScheme.onSurface,
fontWeight: FontWeight.w500,
),
),
),
),
);
},
],
),
),
);
}).toList(),
);
@@ -412,6 +426,13 @@ class _InteractiveSearchExampleState extends State<_InteractiveSearchExample> {
@override
Widget build(BuildContext context) {
final colorScheme = Theme.of(context).colorScheme;
// The demo frame grows on the default spatial spring, whose overshoot
// stays under a pixel at this size; reduced motion resizes at once.
final grow = AppMotion.spatial(
context,
const AppMotionSpec(Duration.zero, Curves.linear),
mornye: MornyeMotion.standard,
);
return Container(
padding: const EdgeInsets.all(24),
decoration: BoxDecoration(
@@ -436,10 +457,9 @@ class _InteractiveSearchExampleState extends State<_InteractiveSearchExample> {
},
),
AnimatedSize(
duration: const Duration(milliseconds: 400),
curve: Curves.easeOutBack,
child: _showResult
_resize(
grow,
_showResult
// The result is a plain row inside the demo frame, not a
// second card.
? Padding(
@@ -504,6 +524,16 @@ class _InteractiveSearchExampleState extends State<_InteractiveSearchExample> {
),
);
}
// A zero-length AnimatedSize re-dirties itself during layout.
static Widget _resize(AppMotionSpec motion, Widget child) =>
motion.duration == Duration.zero
? child
: AnimatedSize(
duration: motion.duration,
curve: motion.curve,
child: child,
);
}
class _InteractiveDownloadExample extends StatefulWidget {
@@ -551,6 +581,10 @@ class _InteractiveDownloadExampleState
@override
Widget build(BuildContext context) {
final colorScheme = Theme.of(context).colorScheme;
final tint = AppMotion.effects(
context,
const AppMotionSpec(Duration(milliseconds: 300), Curves.linear),
);
return LayoutBuilder(
builder: (context, constraints) {
final cardWidth = constraints.maxWidth;
@@ -639,7 +673,8 @@ class _InteractiveDownloadExampleState
widthFactor: 1,
heightFactor: 1,
child: AnimatedContainer(
duration: const Duration(milliseconds: 300),
duration: tint.duration,
curve: tint.curve,
padding: EdgeInsets.all(buttonPadding),
decoration: BoxDecoration(
color: _isCompleted
@@ -713,6 +748,18 @@ class _TutorialPage extends StatelessWidget {
final scale = (shortestSide / 390).clamp(0.86, 1.05);
final isActive = currentIndex == index;
// The icon drops into place on the default spatial spring, which lands
// with a slight overshoot in Material and none in Mornye; the text
// fades on the effects spring.
final drop = AppMotion.spatial(
context,
const AppMotionSpec(Duration.zero, Curves.linear),
mornye: MornyeMotion.standard,
);
final fade = AppMotion.effects(
context,
const AppMotionSpec(Duration(milliseconds: 500), Curves.easeOut),
);
return LayoutBuilder(
builder: (context, constraints) {
@@ -739,8 +786,8 @@ class _TutorialPage extends StatelessWidget {
children: [
SizedBox(height: topGap),
AnimatedContainer(
duration: const Duration(milliseconds: 500),
curve: Curves.easeOutBack,
duration: drop.duration,
curve: drop.curve,
transform: Matrix4.translationValues(
0,
isActive ? 0 : -20,
@@ -759,9 +806,9 @@ class _TutorialPage extends StatelessWidget {
),
SizedBox(height: iconTextGap),
AnimatedOpacity(
duration: const Duration(milliseconds: 500),
duration: fade.duration,
opacity: isActive ? 1.0 : 0.0,
curve: Curves.easeOut,
curve: fade.curve,
child: Text(
title,
style: Theme.of(context).textTheme.headlineLarge
@@ -775,9 +822,9 @@ class _TutorialPage extends StatelessWidget {
),
SizedBox(height: descriptionGap),
AnimatedOpacity(
duration: const Duration(milliseconds: 500),
duration: fade.duration,
opacity: isActive ? 1.0 : 0.0,
curve: Curves.easeOut,
curve: fade.curve,
child: Text(
description,
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
+64
View File
@@ -0,0 +1,64 @@
import 'package:material_ui/material_ui.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mornye/l10n/l10n.dart';
import 'package:mornye/screens/tutorial_screen.dart';
import 'package:mornye/widgets/animation_utils.dart';
Widget _tutorial({bool reduced = false}) => ProviderScope(
child: MaterialApp(
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: MediaQuery(
data: MediaQueryData(
size: const Size(400, 800),
disableAnimations: reduced,
),
child: const TutorialScreen(),
),
),
);
double _page(WidgetTester tester) =>
tester.widget<PageView>(find.byType(PageView)).controller!.page!;
Finder _next(WidgetTester tester) => find.text(
AppLocalizations.of(tester.element(find.byType(TutorialScreen))).setupNext,
);
void main() {
testWidgets('Next turns the page on a spring that stops at the page', (
tester,
) async {
await tester.pumpWidget(_tutorial());
await tester.pumpAndSettle();
// The welcome tips rise in on the shared staggered reveal.
expect(find.byType(StaggeredListItem), findsNWidgets(3));
await tester.tap(_next(tester));
await tester.pump();
var highest = _page(tester);
var moved = false;
for (var frame = 0; frame < 60; frame++) {
await tester.pump(const Duration(milliseconds: 16));
moved = moved || (_page(tester) > 0 && _page(tester) < 1);
highest = highest > _page(tester) ? highest : _page(tester);
}
expect(moved, isTrue);
// A page never travels past the next one.
expect(highest, lessThan(1.001));
await tester.pumpAndSettle();
expect(_page(tester), 1);
});
testWidgets('reduced motion shows the next page at once', (tester) async {
await tester.pumpWidget(_tutorial(reduced: true));
await tester.pumpAndSettle();
expect(find.byType(StaggeredListItem), findsNWidgets(3));
await tester.tap(_next(tester));
await tester.pump();
// The page is there in the first frame, not on the way.
expect(_page(tester), 1);
});
}