diff --git a/lib/widgets/mornye_landscape_player.dart b/lib/widgets/mornye_landscape_player.dart index eb07326c4..6a8ea943f 100644 --- a/lib/widgets/mornye_landscape_player.dart +++ b/lib/widgets/mornye_landscape_player.dart @@ -111,198 +111,222 @@ class _MornyeLandscapePlayerState extends State { @override Widget build(BuildContext context) => Listener( - onPointerDown: (_) { - _hideTimer?.cancel(); - if (!_actionsVisible) setState(() => _actionsVisible = true); - }, + onPointerDown: (_) => _hideTimer?.cancel(), onPointerUp: (_) => _scheduleHide(), onPointerCancel: (_) => _scheduleHide(), child: Padding( padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 24), child: Row( children: [ - Expanded(child: widget.artwork), Expanded( - child: Column( - children: [ - Padding( - padding: const EdgeInsets.fromLTRB(20, 12, 20, 0), - child: widget.header, - ), - const SizedBox(height: 8), - Expanded( - child: LayoutBuilder( - builder: (context, constraints) => Stack( - fit: StackFit.expand, - children: [ - AnimatedSwitcher( - duration: MediaQuery.disableAnimationsOf(context) - ? Duration.zero - : const Duration(milliseconds: 180), - layoutBuilder: (current, previous) => Stack( - fit: StackFit.expand, - children: [ - for (final child in [...previous, ?current]) - IgnorePointer( - key: child.key, - ignoring: child != current, - child: ExcludeSemantics( - excluding: child != current, - child: child, - ), - ), - ], - ), - child: widget.page == 0 - ? SingleChildScrollView( - key: const ValueKey('landscape-controls'), - child: ConstrainedBox( - constraints: BoxConstraints( - minHeight: constraints.maxHeight, - ), - child: Column( - mainAxisAlignment: - MainAxisAlignment.spaceEvenly, - children: [ - widget.controls, - ?widget.volume, - const SizedBox(height: 48), - ], + child: GestureDetector( + behavior: HitTestBehavior.translucent, + onTap: + widget.page == 1 && + !isAndroidTv && + !MediaQuery.accessibleNavigationOf(context) + ? () { + setState(() => _actionsVisible = !_actionsVisible); + _scheduleHide(); + } + : null, + child: widget.artwork, + ), + ), + Expanded( + child: Listener( + behavior: HitTestBehavior.translucent, + onPointerDown: (_) { + if (!_actionsVisible) { + setState(() => _actionsVisible = true); + } + }, + child: Column( + children: [ + Padding( + padding: const EdgeInsets.fromLTRB(20, 12, 20, 0), + child: widget.header, + ), + const SizedBox(height: 8), + Expanded( + child: LayoutBuilder( + builder: (context, constraints) => Stack( + fit: StackFit.expand, + children: [ + AnimatedSwitcher( + duration: MediaQuery.disableAnimationsOf(context) + ? Duration.zero + : const Duration(milliseconds: 180), + layoutBuilder: (current, previous) => Stack( + fit: StackFit.expand, + children: [ + for (final child in [...previous, ?current]) + IgnorePointer( + key: child.key, + ignoring: child != current, + child: ExcludeSemantics( + excluding: child != current, + child: child, ), ), - ) - : Padding( - key: ValueKey(widget.page), - padding: EdgeInsets.only( - bottom: widget.page == 2 ? 48 : 0, - ), - child: widget.page == 2 - ? widget.queue - : Stack( - fit: StackFit.expand, - children: [ - _LandscapeLyricsViewport( - controlsVisible: _actionsVisible, - child: widget.lyrics, - ), - if (widget.lyricsOptions != null) - PositionedDirectional( - start: 20, - bottom: 52, - child: IgnorePointer( - ignoring: !_actionsVisible, - child: AnimatedOpacity( - opacity: _actionsVisible - ? 1 - : 0, - duration: - MediaQuery.disableAnimationsOf( - context, - ) - ? Duration.zero - : const Duration( - milliseconds: 180, - ), - child: - widget.lyricsOptions!, + ], + ), + child: widget.page == 0 + ? SingleChildScrollView( + key: const ValueKey('landscape-controls'), + child: ConstrainedBox( + constraints: BoxConstraints( + minHeight: constraints.maxHeight, + ), + child: Column( + mainAxisAlignment: + MainAxisAlignment.spaceEvenly, + children: [ + widget.controls, + ?widget.volume, + const SizedBox(height: 48), + ], + ), + ), + ) + : Padding( + key: ValueKey(widget.page), + padding: EdgeInsets.only( + bottom: widget.page == 2 ? 48 : 0, + ), + child: widget.page == 2 + ? widget.queue + : Stack( + fit: StackFit.expand, + children: [ + _LandscapeLyricsViewport( + controlsVisible: + _actionsVisible, + child: widget.lyrics, + ), + if (widget.lyricsOptions != null) + PositionedDirectional( + start: 20, + bottom: 52, + child: IgnorePointer( + ignoring: !_actionsVisible, + child: AnimatedOpacity( + opacity: _actionsVisible + ? 1 + : 0, + duration: + MediaQuery.disableAnimationsOf( + context, + ) + ? Duration.zero + : const Duration( + milliseconds: 180, + ), + child: + widget.lyricsOptions!, + ), ), ), - ), - ], - ), - ), - ), - Positioned( - left: 0, - right: 0, - bottom: 0, - height: 48, - child: GestureDetector( - key: const ValueKey('landscape-actions-reveal'), - behavior: HitTestBehavior.opaque, - onTap: _reveal, - child: IgnorePointer( - ignoring: !_actionsVisible, - child: ExcludeSemantics( - excluding: !_actionsVisible, - child: AnimatedOpacity( - opacity: _actionsVisible ? 1 : 0, - duration: - MediaQuery.disableAnimationsOf(context) - ? Duration.zero - : const Duration(milliseconds: 180), - child: Padding( - padding: const EdgeInsets.symmetric( - horizontal: 20, - ), - child: Row( - mainAxisAlignment: - MainAxisAlignment.spaceBetween, - children: [ - IconButton( - tooltip: widget.page == 1 - ? context.l10n.nowPlayingTabPlayer - : context - .l10n - .nowPlayingTabLyrics, - isSelected: widget.page == 1, - color: Colors.white, - style: IconButton.styleFrom( - backgroundColor: widget.page == 1 - ? Colors.white.withValues( - alpha: 0.16, - ) - : Colors.transparent, + ], ), - icon: const Icon( - CupertinoIcons.quote_bubble, + ), + ), + Positioned( + left: 0, + right: 0, + bottom: 0, + height: 48, + child: GestureDetector( + key: const ValueKey('landscape-actions-reveal'), + behavior: HitTestBehavior.opaque, + onTap: _reveal, + child: IgnorePointer( + ignoring: !_actionsVisible, + child: ExcludeSemantics( + excluding: !_actionsVisible, + child: AnimatedOpacity( + opacity: _actionsVisible ? 1 : 0, + duration: + MediaQuery.disableAnimationsOf(context) + ? Duration.zero + : const Duration(milliseconds: 180), + child: Padding( + padding: const EdgeInsets.symmetric( + horizontal: 20, + ), + child: Row( + mainAxisAlignment: + MainAxisAlignment.spaceBetween, + children: [ + IconButton( + tooltip: widget.page == 1 + ? context + .l10n + .nowPlayingTabPlayer + : context + .l10n + .nowPlayingTabLyrics, + isSelected: widget.page == 1, + color: Colors.white, + style: IconButton.styleFrom( + backgroundColor: widget.page == 1 + ? Colors.white.withValues( + alpha: 0.16, + ) + : Colors.transparent, + ), + icon: const Icon( + CupertinoIcons.quote_bubble, + ), + onPressed: () => + widget.onPageChanged( + widget.page == 1 ? 0 : 1, + ), ), - onPressed: () => widget.onPageChanged( - widget.page == 1 ? 0 : 1, + AudioOutputButton( + color: Colors.white, + onPickerChanged: (open) { + if (!mounted) return; + setState( + () => _audioOutputOpen = open, + ); + _scheduleHide(); + }, ), - ), - AudioOutputButton( - color: Colors.white, - onPickerChanged: (open) { - if (!mounted) return; - setState( - () => _audioOutputOpen = open, - ); - _scheduleHide(); - }, - ), - IconButton( - tooltip: - context.l10n.nowPlayingUpNext, - icon: const Icon( - CupertinoIcons.list_bullet, + IconButton( + tooltip: + context.l10n.nowPlayingUpNext, + icon: const Icon( + CupertinoIcons.list_bullet, + ), + isSelected: widget.page == 2, + color: Colors.white, + style: IconButton.styleFrom( + backgroundColor: widget.page == 2 + ? Colors.white.withValues( + alpha: 0.16, + ) + : Colors.transparent, + ), + onPressed: () => + widget.onPageChanged( + widget.page == 2 ? 0 : 2, + ), ), - isSelected: widget.page == 2, - color: Colors.white, - style: IconButton.styleFrom( - backgroundColor: widget.page == 2 - ? Colors.white.withValues( - alpha: 0.16, - ) - : Colors.transparent, - ), - onPressed: () => widget.onPageChanged( - widget.page == 2 ? 0 : 2, - ), - ), - ], + ], + ), ), ), ), ), ), ), - ), - ], + ], + ), ), ), - ), - ], + ], + ), ), ), ], diff --git a/lib/widgets/mornye_player_layout.dart b/lib/widgets/mornye_player_layout.dart index 8a315ad5c..0e142e364 100644 --- a/lib/widgets/mornye_player_layout.dart +++ b/lib/widgets/mornye_player_layout.dart @@ -141,7 +141,7 @@ class MornyePlayerLayout extends ConsumerWidget { 0.0, (stage.maxHeight - (artworkOnly ? 24 : 8)).clamp(0.0, 360.0), ); - final ratio = artworkAspectRatio ?? 1.0; + final ratio = artworkOnly ? 1.0 : artworkAspectRatio ?? 1.0; final artWidth = ratio < 1 ? artSize * ratio : artSize; final artHeight = ratio > 1 ? artSize / ratio : artSize; final fullBleed = !insetArtwork && !artworkOnly; diff --git a/test/mornye_landscape_player_test.dart b/test/mornye_landscape_player_test.dart index a42838fee..e38679797 100644 --- a/test/mornye_landscape_player_test.dart +++ b/test/mornye_landscape_player_test.dart @@ -15,6 +15,10 @@ void main() { WidgetTester tester, { GlobalKey? capture, bool blur = true, + bool playing = true, + TextDirection direction = TextDirection.ltr, + double? playerWidth, + bool accessibleNavigation = false, }) async { tester.view.physicalSize = const Size(852, 393); tester.view.devicePixelRatio = 1; @@ -28,24 +32,38 @@ void main() { backdropBlurEnabledProvider.overrideWithValue(blur), ], child: MaterialApp( + builder: (context, child) => MediaQuery( + data: MediaQuery.of( + context, + ).copyWith(accessibleNavigation: accessibleNavigation), + child: Directionality(textDirection: direction, child: child!), + ), theme: MornyeTheme.build(Brightness.dark), localizationsDelegates: AppLocalizations.localizationsDelegates, supportedLocales: AppLocalizations.supportedLocales, home: Scaffold( backgroundColor: const Color(0xFF303030), - body: RepaintBoundary( - key: capture, - child: StatefulBuilder( - builder: (context, setState) => MornyeLandscapePlayer( - page: page, - isPlaying: true, - onPageChanged: (value) => setState(() => page = value), - artwork: const SizedBox.expand(), - header: const SizedBox(height: 48), - lyrics: const CustomPaint(painter: _Stripes()), - queue: const SizedBox.expand(), - controls: const SizedBox(height: 68), - volume: const SizedBox(height: 48), + body: SizedBox( + width: playerWidth, + child: RepaintBoundary( + key: capture, + child: StatefulBuilder( + builder: (context, setState) => MornyeLandscapePlayer( + page: page, + isPlaying: playing, + onPageChanged: (value) => setState(() => page = value), + artwork: const SizedBox.expand( + child: ColoredBox( + key: ValueKey('artwork'), + color: Colors.transparent, + ), + ), + header: const SizedBox(height: 48), + lyrics: const CustomPaint(painter: _Stripes()), + queue: const SizedBox.expand(), + controls: const SizedBox(height: 68), + volume: const SizedBox(height: 48), + ), ), ), ), @@ -56,6 +74,52 @@ void main() { await tester.pumpAndSettle(); } + for (final direction in TextDirection.values) { + for (final playing in [false, true]) { + testWidgets('artwork toggles actions in a constrained $direction player ' + '(playing: $playing)', (tester) async { + await pumpPlayer( + tester, + playing: playing, + direction: direction, + playerWidth: 600, + ); + final toggle = find.byIcon(CupertinoIcons.quote_bubble); + final artwork = find.byKey(const ValueKey('artwork')); + expect(toggle.hitTestable(), findsOneWidget); + await tester.tap(artwork); + await tester.pumpAndSettle(); + expect(toggle.hitTestable(), findsNothing); + await tester.tap(artwork); + await tester.pumpAndSettle(); + expect(toggle.hitTestable(), findsOneWidget); + + await tester.tap(artwork); + await tester.pumpAndSettle(); + expect(toggle.hitTestable(), findsNothing); + await tester.tap( + find.byKey(const ValueKey('landscape-lyrics-viewport')), + ); + await tester.pumpAndSettle(); + expect(toggle.hitTestable(), findsOneWidget); + expect(tester.takeException(), isNull); + }); + } + } + + testWidgets('accessible navigation keeps actions visible on artwork taps', ( + tester, + ) async { + await pumpPlayer(tester, accessibleNavigation: true); + await tester.tap(find.byKey(const ValueKey('artwork'))); + await tester.pump(const Duration(seconds: 6)); + expect( + find.byIcon(CupertinoIcons.quote_bubble).hitTestable(), + findsOneWidget, + ); + expect(tester.takeException(), isNull); + }); + testWidgets('landscape selected tabs use the neutral portrait colors', ( tester, ) async { diff --git a/test/now_playing_lyrics_transition_test.dart b/test/now_playing_lyrics_transition_test.dart index 102fdf0fc..e7795f8f8 100644 --- a/test/now_playing_lyrics_transition_test.dart +++ b/test/now_playing_lyrics_transition_test.dart @@ -865,6 +865,72 @@ void main() { }, ); + for (final ratio in [0.75, 16 / 9]) { + testWidgets('landscape motion cover stays square across tabs and rotation ' + '(video ratio: $ratio)', (tester) async { + final queue = [item('first'), item('second')]; + final controller = _QueueController( + (index) => mediaItems.add(queue[index]), + ); + await pumpNowPlaying( + tester, + theme: MornyeTheme.build(Brightness.dark), + size: const Size(852, 393), + motionArtwork: MotionArtwork('file:///cover.mp4', aspectRatio: ratio), + queue: queue, + controller: controller, + playback: PlaybackState(queueIndex: 0), + ); + mediaItems.add(queue.first); + await settlePlayer(tester); + + final artwork = find.byKey(const ValueKey('full-player-artwork')); + void expectSquareCover() { + final size = tester.getSize(artwork); + expect(size.width, greaterThan(140)); + expect(size.width, closeTo(size.height, 0.1)); + final clip = find.descendant( + of: artwork, + matching: find.byType(ClipRRect), + ); + expect(clip, findsOneWidget); + expect(tester.getSize(clip), size); + } + + expectSquareCover(); + await tester.tap(findAppIcon(CupertinoIcons.quote_bubble)); + await settlePlayer(tester); + expectSquareCover(); + await tester.tap(artwork); + await settlePlayer(tester); + final toggle = findAppIcon(CupertinoIcons.quote_bubble); + expect(toggle.hitTestable(), findsNothing); + await tester.tap(artwork); + await settlePlayer(tester); + expect(toggle.hitTestable(), findsOneWidget); + + await tester.drag(artwork, const Offset(-110, 0)); + await settlePlayer(tester); + expect(controller.selected, [1]); + expect(find.text('Second').hitTestable(), findsOneWidget); + expect(toggle.hitTestable(), findsOneWidget); + expectSquareCover(); + await tester.drag(artwork, const Offset(110, 0)); + await settlePlayer(tester); + expect(controller.selected, [1, 0]); + + await tester.tap(findAppIcon(CupertinoIcons.list_bullet)); + await settlePlayer(tester); + expectSquareCover(); + tester.view.physicalSize = const Size(393, 852); + await settlePlayer(tester); + tester.view.physicalSize = const Size(852, 393); + await settlePlayer(tester); + expectSquareCover(); + expect(tester.takeException(), isNull); + }); + } + testWidgets('custom glass keeps live lyrics under the finger on reversal', ( tester, ) async {