Add fullscreen queue view
This commit is contained in:
1 parent
4ab6ff0e28
commit
df9eef3058
1 file changed
+175
-6
@@ -11,6 +11,9 @@ struct FullscreenPlayerView: View {
|
||||
@State private var isFinishingDragDismissal = false
|
||||
@State private var hasCheckedDismissDragStart = false
|
||||
@State private var isActiveDismissDrag = false
|
||||
@State private var isQueuePresented = false
|
||||
@State private var isShuffleEnabled = false
|
||||
@State private var isAutoplayEnabled = false
|
||||
|
||||
private enum SliderKind {
|
||||
case progress
|
||||
@@ -51,6 +54,10 @@ struct FullscreenPlayerView: View {
|
||||
.position(x: size.width * 0.5, y: size.height * 0.08)
|
||||
.accessibilityLabel("Swipe down to close player")
|
||||
|
||||
if isQueuePresented {
|
||||
queueContent(size: size)
|
||||
.transition(.opacity)
|
||||
} else {
|
||||
artwork
|
||||
.frame(width: artworkLength, height: artworkLength)
|
||||
.clipShape(RoundedRectangle(cornerRadius: 14, style: .continuous))
|
||||
@@ -58,7 +65,7 @@ struct FullscreenPlayerView: View {
|
||||
.position(x: size.width * 0.5, y: size.height * 0.31)
|
||||
|
||||
Image(systemName: "ellipsis")
|
||||
.font(.system(size: 18, weight: .semibold))
|
||||
.font(.system(size: 16, weight: .semibold))
|
||||
.frame(width: size.width - 72, alignment: .trailing)
|
||||
.foregroundStyle(.white)
|
||||
.position(x: size.width * 0.5, y: size.height * 0.60)
|
||||
@@ -75,6 +82,7 @@ struct FullscreenPlayerView: View {
|
||||
.foregroundStyle(.white)
|
||||
.frame(width: size.width * 0.68, alignment: .leading)
|
||||
.position(x: size.width * 0.41, y: size.height * 0.60)
|
||||
}
|
||||
|
||||
seekControls
|
||||
.frame(width: size.width * 0.86)
|
||||
@@ -100,9 +108,24 @@ struct FullscreenPlayerView: View {
|
||||
Spacer()
|
||||
Image(systemName: "airplay.audio")
|
||||
Spacer()
|
||||
Image(systemName: "list.bullet")
|
||||
Button {
|
||||
withAnimation(.spring(response: 0.42, dampingFraction: 0.88)) {
|
||||
isQueuePresented.toggle()
|
||||
}
|
||||
.font(.system(size: 18, weight: .medium))
|
||||
} label: {
|
||||
Image(systemName: "list.bullet")
|
||||
.frame(width: 36, height: 36)
|
||||
.background {
|
||||
if isQueuePresented {
|
||||
Circle().fill(.white.opacity(0.85))
|
||||
}
|
||||
}
|
||||
.foregroundStyle(isQueuePresented ? Color(white: 0.38) : .white.opacity(0.85))
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.accessibilityLabel(isQueuePresented ? "Hide queue" : "Show queue")
|
||||
}
|
||||
.font(.system(size: 16, weight: .medium))
|
||||
.foregroundStyle(.white.opacity(0.85))
|
||||
.frame(width: size.width * 0.58)
|
||||
.position(x: size.width * 0.5, y: size.height * 0.94)
|
||||
@@ -149,6 +172,152 @@ struct FullscreenPlayerView: View {
|
||||
.background(.ultraThinMaterial)
|
||||
}
|
||||
|
||||
private func queueContent(size: CGSize) -> some View {
|
||||
VStack(alignment: .leading, spacing: 18) {
|
||||
HStack(spacing: 14) {
|
||||
queueArtwork(for: track, size: 56)
|
||||
|
||||
VStack(alignment: .leading, spacing: 3) {
|
||||
Text(track?.name ?? "")
|
||||
.font(.system(size: 22, weight: .semibold))
|
||||
.lineLimit(1)
|
||||
Text(artistNames)
|
||||
.font(.system(size: 17))
|
||||
.foregroundStyle(.white.opacity(0.68))
|
||||
.lineLimit(1)
|
||||
}
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
|
||||
Image(systemName: "ellipsis")
|
||||
.font(.system(size: 16, weight: .semibold))
|
||||
.frame(width: 32)
|
||||
}
|
||||
.foregroundStyle(.white)
|
||||
.frame(height: 78)
|
||||
|
||||
HStack(spacing: 12) {
|
||||
queueModeButton(symbol: "shuffle", isSelected: isShuffleEnabled) {
|
||||
isShuffleEnabled.toggle()
|
||||
if isShuffleEnabled { player.shuffleUpcoming() }
|
||||
}
|
||||
queueModeButton(
|
||||
symbol: player.repeatMode == .one ? "repeat.1" : "repeat",
|
||||
isSelected: player.repeatMode != .off
|
||||
) {
|
||||
player.cycleRepeat()
|
||||
}
|
||||
queueModeButton(symbol: "infinity", isSelected: isAutoplayEnabled) {
|
||||
isAutoplayEnabled.toggle()
|
||||
}
|
||||
queueModeButton(symbol: "shuffle", isSelected: false, action: {})
|
||||
.opacity(0.35)
|
||||
.disabled(true)
|
||||
}
|
||||
|
||||
Text("Continue Playing")
|
||||
.font(.system(size: 20, weight: .semibold))
|
||||
.foregroundStyle(.white)
|
||||
.padding(.top, 4)
|
||||
|
||||
ScrollView {
|
||||
LazyVStack(spacing: 10) {
|
||||
ForEach(Array(player.upcomingTracks.enumerated()), id: \.offset) { index, queuedTrack in
|
||||
Button {
|
||||
player.playQueuedTrack(at: player.previousTracks.count + index + 1)
|
||||
} label: {
|
||||
HStack(spacing: 14) {
|
||||
queueArtwork(for: queuedTrack, size: 46)
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text(queuedTrack.name)
|
||||
.font(.system(size: 18, weight: .medium))
|
||||
.foregroundStyle(.white)
|
||||
.lineLimit(1)
|
||||
Text(artistNames(for: queuedTrack))
|
||||
.font(.system(size: 15))
|
||||
.foregroundStyle(.white.opacity(0.68))
|
||||
.lineLimit(1)
|
||||
}
|
||||
Spacer(minLength: 8)
|
||||
Image(systemName: "line.3.horizontal")
|
||||
.font(.system(size: 16, weight: .medium))
|
||||
.foregroundStyle(.white.opacity(0.35))
|
||||
}
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.contentShape(Rectangle())
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
|
||||
if player.upcomingTracks.isEmpty {
|
||||
Text("No more songs in the queue")
|
||||
.font(.system(size: 15))
|
||||
.foregroundStyle(.white.opacity(0.65))
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.padding(.vertical, 18)
|
||||
}
|
||||
}
|
||||
}
|
||||
.scrollIndicators(.hidden)
|
||||
}
|
||||
.padding(.horizontal, size.width * 0.08)
|
||||
.padding(.top, size.height * 0.12)
|
||||
.frame(maxWidth: .infinity, alignment: .topLeading)
|
||||
.frame(height: size.height * 0.66, alignment: .top)
|
||||
.foregroundStyle(.white)
|
||||
}
|
||||
|
||||
private func queueModeButton(
|
||||
symbol: String,
|
||||
isSelected: Bool,
|
||||
action: @escaping () -> Void
|
||||
) -> some View {
|
||||
Button(action: action) {
|
||||
Image(systemName: symbol)
|
||||
.font(.system(size: 18, weight: .semibold))
|
||||
.foregroundStyle(isSelected ? Color(white: 0.4) : .white)
|
||||
.frame(maxWidth: .infinity)
|
||||
.frame(height: 44)
|
||||
.background(isSelected ? Color.white.opacity(0.88) : Color.white.opacity(0.14))
|
||||
.clipShape(Capsule())
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private func queueArtwork(for track: Track?, size: CGFloat) -> some View {
|
||||
if let url = track.flatMap({ player.artworkURL(for: $0) }) {
|
||||
AsyncImage(url: url) { phase in
|
||||
if let image = phase.image {
|
||||
image.resizable().scaledToFill()
|
||||
} else {
|
||||
queueArtworkPlaceholder
|
||||
}
|
||||
}
|
||||
.frame(width: size, height: size)
|
||||
.clipShape(RoundedRectangle(cornerRadius: 8, style: .continuous))
|
||||
} else {
|
||||
queueArtworkPlaceholder
|
||||
.frame(width: size, height: size)
|
||||
.clipShape(RoundedRectangle(cornerRadius: 8, style: .continuous))
|
||||
}
|
||||
}
|
||||
|
||||
private var queueArtworkPlaceholder: some View {
|
||||
Image(systemName: "music.note")
|
||||
.font(.system(size: 22, weight: .light))
|
||||
.foregroundStyle(.white.opacity(0.75))
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
.background(.white.opacity(0.12))
|
||||
}
|
||||
|
||||
private func artistNames(for track: Track) -> String {
|
||||
let names = track.artists.compactMap { reference -> String? in
|
||||
guard case .value(let artist) = reference else { return nil }
|
||||
return artist.name
|
||||
}
|
||||
return names.isEmpty ? "Unknown Artist" : names.joined(separator: ", ")
|
||||
}
|
||||
|
||||
private var seekControls: some View {
|
||||
VStack(spacing: 10) {
|
||||
GeometryReader { geometry in
|
||||
@@ -235,7 +404,7 @@ struct FullscreenPlayerView: View {
|
||||
HStack {
|
||||
Button(action: player.previous) {
|
||||
Image(systemName: "backward.end.fill")
|
||||
.font(.system(size: 30, weight: .semibold))
|
||||
.font(.system(size: 26, weight: .semibold))
|
||||
.frame(width: 64, height: 64)
|
||||
}
|
||||
.accessibilityLabel("Previous track")
|
||||
@@ -246,7 +415,7 @@ struct FullscreenPlayerView: View {
|
||||
if player.isPlaying { player.pause() } else { player.play() }
|
||||
} label: {
|
||||
Image(systemName: displayedIsPlaying ? "pause.fill" : "play.fill")
|
||||
.font(.system(size: 36, weight: .semibold))
|
||||
.font(.system(size: 32, weight: .semibold))
|
||||
.frame(width: 76, height: 76)
|
||||
.scaleEffect(playIconScale)
|
||||
}
|
||||
@@ -256,7 +425,7 @@ struct FullscreenPlayerView: View {
|
||||
|
||||
Button(action: player.next) {
|
||||
Image(systemName: "forward.end.fill")
|
||||
.font(.system(size: 30, weight: .semibold))
|
||||
.font(.system(size: 26, weight: .semibold))
|
||||
.frame(width: 64, height: 64)
|
||||
}
|
||||
.accessibilityLabel("Next track")
|
||||
|
||||
Reference in new issue
Block a user