feat(player): immersive Material lyrics while idle

In portrait, Material lyrics left five seconds without a touch while
playing now hide the player chrome, as Mornye already does: the app bar
buttons fade, and the title, transport and footer fold away on the slow
spatial spring so the lyrics fill the screen. A tap, pausing or
accessible navigation brings them back; landscape keeps its two panes.
This commit is contained in:
zarzet committed 2026-10-25 15:45:49 +07:00
1 parent 8e7d792c29
commit ac6dc3c2eb
4 files changed
+198 -44

No files matched your search

+64 -34
View File
@@ -65,14 +65,23 @@ class _FadingAppBar extends StatelessWidget implements PreferredSizeWidget {
final Animation<double> opacity;
final AppBar child;
const _FadingAppBar({required this.opacity, required this.child});
/// Material's immersive lyrics fade the bar's buttons away too.
final bool hidden;
const _FadingAppBar({
required this.opacity,
required this.child,
this.hidden = false,
});
@override
Size get preferredSize => child.preferredSize;
@override
Widget build(BuildContext context) =>
FadeTransition(opacity: opacity, child: child);
Widget build(BuildContext context) => FadeTransition(
opacity: opacity,
child: PlayerLyricsControlsVisibility(hidden: hidden, child: child),
);
}
class NowPlayingScreen extends ConsumerStatefulWidget {
@@ -168,7 +177,7 @@ class _NowPlayingScreenState extends ConsumerState<NowPlayingScreen> {
super.didChangeDependencies();
final size = MediaQuery.sizeOf(context);
_landscape = context.isMornye && size.width > size.height;
if (_landscape || MediaQuery.accessibleNavigationOf(context)) {
if (!_lyricsAutoHideLayout || MediaQuery.accessibleNavigationOf(context)) {
_lyricsControlsHidden = false;
}
_scheduleLyricsControlsHide();
@@ -406,6 +415,7 @@ class _NowPlayingScreenState extends ConsumerState<NowPlayingScreen> {
: colorScheme.surface,
appBar: _FadingAppBar(
opacity: contentOpacity,
hidden: !mornye && _lyricsImmersive,
child: AppBar(
backgroundColor: mornye || materialFullScreen
? Colors.transparent
@@ -532,6 +542,7 @@ class _NowPlayingScreenState extends ConsumerState<NowPlayingScreen> {
seekPreview: _seekPreview,
colorScheme: colorScheme,
showLyrics: _currentPage == 1,
immersive: _lyricsImmersive,
fullScreenArtwork: materialFullScreen,
lyricsBuilder: (_) =>
_lyricsSection(colorScheme, isActive: true),
@@ -631,6 +642,7 @@ class _NowPlayingScreenState extends ConsumerState<NowPlayingScreen> {
],
),
),
collapse: true,
),
],
),
@@ -638,7 +650,7 @@ class _NowPlayingScreenState extends ConsumerState<NowPlayingScreen> {
),
);
if (!mornye) {
if (!materialFullScreen) return player;
if (!materialFullScreen) return _lyricsPointerListener(player);
return Stack(
fit: StackFit.expand,
children: [
@@ -647,7 +659,7 @@ class _NowPlayingScreenState extends ConsumerState<NowPlayingScreen> {
colorScheme: colorScheme,
showArtwork: _currentPage != 1,
),
player,
_lyricsPointerListener(player),
],
);
}
@@ -688,34 +700,42 @@ class _NowPlayingScreenState extends ConsumerState<NowPlayingScreen> {
: null,
),
),
Listener(
behavior: HitTestBehavior.translucent,
onPointerDown: (event) {
if (!_canAutoHideLyricsControls) return;
if (_lyricsPointers.isEmpty) _lyricsPointerMoved = false;
_lyricsPointers[event.pointer] = event.position;
_lyricsIdleTimer?.cancel();
},
onPointerMove: (event) {
final origin = _lyricsPointers[event.pointer];
if (origin != null && (event.position - origin).distance > 12) {
_lyricsPointerMoved = true;
}
},
onPointerUp: (event) => _endLyricsInteraction(event.pointer),
onPointerCancel: (event) =>
_endLyricsInteraction(event.pointer, cancelled: true),
child: player,
),
_lyricsPointerListener(player),
],
),
),
);
}
/// A touch on the lyrics page holds the controls; a tap brings hidden
/// ones back.
Widget _lyricsPointerListener(Widget child) => Listener(
behavior: HitTestBehavior.translucent,
onPointerDown: (event) {
if (!_canAutoHideLyricsControls) return;
if (_lyricsPointers.isEmpty) _lyricsPointerMoved = false;
_lyricsPointers[event.pointer] = event.position;
_lyricsIdleTimer?.cancel();
},
onPointerMove: (event) {
final origin = _lyricsPointers[event.pointer];
if (origin != null && (event.position - origin).distance > 12) {
_lyricsPointerMoved = true;
}
},
onPointerUp: (event) => _endLyricsInteraction(event.pointer),
onPointerCancel: (event) =>
_endLyricsInteraction(event.pointer, cancelled: true),
child: child,
);
void _toggleMaterialLyrics() {
if (_toggleInspector(1)) return;
setState(() => _currentPage = _currentPage == 1 ? 0 : 1);
setState(() {
_currentPage = _currentPage == 1 ? 0 : 1;
_lyricsControlsHidden = false;
});
_scheduleLyricsControlsHide();
if (_currentPage == 1) {
unawaited(
_trackMetadata.load(
@@ -748,9 +768,16 @@ class _NowPlayingScreenState extends ConsumerState<NowPlayingScreen> {
}
}
/// Lyrics fill the column, so idle controls can hide: Mornye in portrait,
/// and Material's single portrait column (landscape keeps two panes, and
/// the desktop opens lyrics in the inspector).
bool get _lyricsAutoHideLayout => context.isMornye
? !_landscape
: !widget.embedded &&
MediaQuery.orientationOf(context) == Orientation.portrait;
bool get _canAutoHideLyricsControls =>
context.isMornye &&
!_landscape &&
_lyricsAutoHideLayout &&
_currentPage == 1 &&
ref.read(playbackPlayingProvider) &&
!MediaQuery.accessibleNavigationOf(context);
@@ -804,12 +831,15 @@ class _NowPlayingScreenState extends ConsumerState<NowPlayingScreen> {
return false;
}
Widget _autoHidingLyricsControls(Widget child) => context.isMornye
? PlayerLyricsControlsVisibility(
hidden: _currentPage == 1 && _lyricsControlsHidden && !_landscape,
child: child,
)
: child;
bool get _lyricsImmersive =>
_currentPage == 1 && _lyricsControlsHidden && _lyricsAutoHideLayout;
/// Mornye fades the controls in place; Material folds a [collapse] row
/// away so the lyrics take its room.
Widget _autoHidingLyricsControls(Widget child, {bool collapse = false}) =>
!context.isMornye && collapse
? PlayerLyricsControlsCollapse(hidden: _lyricsImmersive, child: child)
: PlayerLyricsControlsVisibility(hidden: _lyricsImmersive, child: child);
Widget _lyricsSection(
ColorScheme colorScheme, {
+21 -10
View File
@@ -12,6 +12,7 @@ import 'package:mornye/theme/app_motion.dart';
import 'package:mornye/utils/playback_seek_preview.dart';
import 'package:mornye/widgets/player_artwork.dart';
import 'package:mornye/widgets/player_gesture_regions.dart';
import 'package:mornye/widgets/player_lyrics_controls.dart';
import 'package:mornye/widgets/player_metadata_title.dart';
import 'package:mornye/widgets/player_playback_controls.dart';
import 'package:mornye/widgets/player_volume_control.dart';
@@ -27,6 +28,7 @@ class MaterialPlayerLayout extends StatelessWidget {
required this.lyricsBuilder,
required this.onOpenQueue,
this.fullScreenArtwork = false,
this.immersive = false,
});
final MediaItem mediaItem;
@@ -40,6 +42,10 @@ class MaterialPlayerLayout extends StatelessWidget {
/// The page backdrop paints the cover; this area only keeps its gestures.
final bool fullScreenArtwork;
/// Lyrics left idle while playing: the title and controls fold away so
/// the lyrics fill the column.
final bool immersive;
@override
Widget build(BuildContext context) {
return LayoutBuilder(
@@ -180,16 +186,21 @@ class MaterialPlayerLayout extends StatelessWidget {
child: Column(
children: [
Expanded(child: visual()),
const SizedBox(height: 12),
PlayerQueueSwipeRegion(
onOpenQueue: onOpenQueue,
child: Column(
mainAxisSize: MainAxisSize.min,
// Short phones keep the room for artwork and lyrics; the
// hardware buttons still set the volume there.
children: _metadataAndControls(
context,
showVolume: constraints.maxHeight >= 600,
PlayerLyricsControlsCollapse(
hidden: immersive && showLyrics,
child: Padding(
padding: const EdgeInsets.only(top: 12),
child: PlayerQueueSwipeRegion(
onOpenQueue: onOpenQueue,
child: Column(
mainAxisSize: MainAxisSize.min,
// Short phones keep the room for artwork and lyrics;
// the hardware buttons still set the volume there.
children: _metadataAndControls(
context,
showVolume: constraints.maxHeight >= 600,
),
),
),
),
),
+49
View File
@@ -1,4 +1,53 @@
import 'package:flutter/material.dart';
import 'package:mornye/theme/app_motion.dart';
/// Material's immersive lyrics: fades the controls and folds their height
/// away, sliding them down, so the lyrics take the room they leave. The
/// controls stay mounted, keeping their state.
class PlayerLyricsControlsCollapse extends StatelessWidget {
const PlayerLyricsControlsCollapse({
super.key,
required this.hidden,
required this.child,
});
final bool hidden;
final Widget child;
@override
Widget build(BuildContext context) {
// The slow spatial spring is critically damped: the fold never
// overshoots into a gap below the controls.
final motion = AppMotion.spatialSlow(
context,
AppMotionSpec(
MediaQuery.disableAnimationsOf(context)
? Duration.zero
: const Duration(milliseconds: 350),
Curves.easeInOutCubic,
),
);
return IgnorePointer(
ignoring: hidden,
child: ExcludeSemantics(
excluding: hidden,
child: TweenAnimationBuilder<double>(
tween: Tween(end: hidden ? 0 : 1),
duration: motion.duration,
curve: motion.curve,
builder: (context, shown, child) => ClipRect(
child: Align(
alignment: Alignment.topCenter,
heightFactor: shown.clamp(0, 1),
child: Opacity(opacity: shown.clamp(0, 1), child: child),
),
),
child: child,
),
),
);
}
}
/// Fades controls without changing the lyric viewport or active scroll gesture.
class PlayerLyricsControlsVisibility extends StatelessWidget {
@@ -1423,6 +1423,70 @@ void main() {
);
}
for (final landscape in [false, true]) {
testWidgets(
'Material lyrics fill the player while idle (landscape: $landscape)',
(tester) async {
metadataOverrides['lyrics'] =
'[00:00.00]First lyric\n[01:00.00]Second line';
await pumpNowPlaying(
tester,
theme: AppTheme.light(),
size: landscape ? const Size(852, 393) : const Size(393, 852),
playback: PlaybackState(playing: true),
);
mediaItems.add(item('many'));
await settlePlayer(tester);
final lyricsToggle = find.byKey(
const ValueKey('material-lyrics-toggle'),
);
final transport = find.byType(ExpressivePlaybackTransport);
final minimize = find.byKey(const ValueKey('now-playing-minimize'));
await tester.tap(lyricsToggle);
await tester.pump();
await completeLyrics(tester);
await tester.pump(const Duration(milliseconds: 4900));
expect(lyricsToggle.hitTestable(), findsOneWidget);
final list = find.byType(ListView);
final height = tester.getSize(list).height;
await tester.pump(const Duration(milliseconds: 100));
await settlePlayer(tester);
if (landscape) {
// Two panes keep the controls beside the lyrics.
expect(lyricsToggle.hitTestable(), findsOneWidget);
expect(tester.takeException(), isNull);
return;
}
expect(lyricsToggle.hitTestable(), findsNothing);
expect(transport.hitTestable(), findsNothing);
expect(minimize.hitTestable(), findsNothing);
// The controls fold away and the lyrics take their room.
expect(tester.getSize(list).height, greaterThan(height + 200));
final bounds = tester.getRect(list);
await tester.tapAt(Offset(bounds.right - 6, bounds.top + 10));
await settlePlayer(tester);
expect(lyricsToggle.hitTestable(), findsOneWidget);
expect(transport.hitTestable(), findsOneWidget);
expect(minimize.hitTestable(), findsOneWidget);
expect(tester.getSize(list).height, closeTo(height, 1));
// Leaving the lyrics shows the cover with its controls.
await tester.pump(const Duration(seconds: 6));
await settlePlayer(tester);
expect(lyricsToggle.hitTestable(), findsNothing);
await tester.tapAt(Offset(bounds.right - 6, bounds.top + 10));
await settlePlayer(tester);
await tester.tap(lyricsToggle);
await settlePlayer(tester);
expect(find.byType(ListView), findsNothing);
await tester.pump(const Duration(seconds: 6));
expect(transport.hitTestable(), findsOneWidget);
expect(tester.takeException(), isNull);
},
);
}
testWidgets(
'accessible navigation keeps lyric controls available while idle',
(tester) async {