Animate mini player playback control
This commit is contained in:
1 parent
77c00cc47e
commit
84675dbfc6
1 file changed
+20
-2
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user