From 84675dbfc695e4249ac0b01abd7e2fc137b4a0eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20T=C3=A4kker?= Date: Fri, 16 Oct 2026 03:26:39 +0200 Subject: [PATCH] Animate mini player playback control --- Music/View/Player/MiniPlayerView.swift | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/Music/View/Player/MiniPlayerView.swift b/Music/View/Player/MiniPlayerView.swift index dd2ab26..c841040 100644 --- a/Music/View/Player/MiniPlayerView.swift +++ b/Music/View/Player/MiniPlayerView.swift @@ -10,6 +10,8 @@ struct MiniPlayerView: View { let onNext: () -> Void let onOpen: () -> Void @State private var displayedIsPlaying: Bool + @State private var playIconScale: CGFloat = 1 + @State private var pendingIsPlaying: Bool? init( track: Track?, @@ -71,12 +73,13 @@ struct MiniPlayerView: View { .onTapGesture(perform: onOpen) Button { - displayedIsPlaying.toggle() + animatePlayIcon(to: !(pendingIsPlaying ?? displayedIsPlaying)) onTogglePlayback() } label: { Image(systemName: displayedIsPlaying ? "pause.fill" : "play.fill") .font(.system(size: usesCompactLayout ? 18 : 21, weight: .medium)) .frame(width: usesCompactLayout ? 34 : 42, height: 32) + .scaleEffect(playIconScale) .contentShape(Rectangle()) } .buttonStyle(.plain) @@ -99,11 +102,26 @@ struct MiniPlayerView: View { .frame(height: 52) .foregroundStyle(.primary) .onChange(of: isPlaying) { _, newValue in - displayedIsPlaying = newValue + animatePlayIcon(to: newValue) } .accessibilityElement(children: .contain) } + private func animatePlayIcon(to newValue: Bool) { + guard (pendingIsPlaying ?? displayedIsPlaying) != newValue else { return } + pendingIsPlaying = newValue + withAnimation(.easeOut(duration: 0.12)) { + playIconScale = 0 + } + DispatchQueue.main.asyncAfter(deadline: .now() + 0.12) { + displayedIsPlaying = newValue + pendingIsPlaying = nil + withAnimation(.easeOut(duration: 0.12)) { + playIconScale = 1 + } + } + } + @ViewBuilder private var artwork: some View { if let artworkURL {