Refine artist page layout
This commit is contained in:
1 parent
20a0048749
commit
437f56f730
1 file changed
+255
-72
@@ -62,6 +62,11 @@ final class ArtistDetailViewModel: ObservableObject {
|
||||
return api.client.configuration.mediaURL(for: file)
|
||||
}
|
||||
|
||||
func artworkURL(for track: Track) -> URL? {
|
||||
guard case .value(let album) = track.album else { return nil }
|
||||
return api.client.configuration.mediaURL(for: album.file)
|
||||
}
|
||||
|
||||
private func loadAllTracks() async throws -> [Track] {
|
||||
var all: [Track] = []
|
||||
var skip = 0
|
||||
@@ -87,6 +92,7 @@ final class ArtistDetailViewModel: ObservableObject {
|
||||
|
||||
struct ArtistDetailView: View {
|
||||
@EnvironmentObject private var player: PlayerManager
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
@StateObject private var viewModel: ArtistDetailViewModel
|
||||
|
||||
init(artistID: String) {
|
||||
@@ -117,6 +123,7 @@ struct ArtistDetailView: View {
|
||||
description: Text("This artist may no longer be available."))
|
||||
}
|
||||
}
|
||||
.toolbar(.hidden, for: .navigationBar)
|
||||
.navigationTitle("")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.tint(.red)
|
||||
@@ -124,89 +131,265 @@ struct ArtistDetailView: View {
|
||||
}
|
||||
|
||||
private func content(_ artist: Artist) -> some View {
|
||||
ScrollView {
|
||||
VStack(alignment: .leading, spacing: 24) {
|
||||
VStack(spacing: 14) {
|
||||
AlbumArtworkView(url: viewModel.artworkURL(for: artist), cornerRadius: 20)
|
||||
.containerRelativeFrame(.horizontal) { length, _ in min(280, length - 40) }
|
||||
.frame(maxWidth: .infinity)
|
||||
.accessibilityLabel("\(artist.name) artist artwork")
|
||||
Text(artist.name).font(.largeTitle.weight(.bold)).multilineTextAlignment(.center)
|
||||
HStack(spacing: 14) {
|
||||
Button { player.play(viewModel.tracks, shuffled: true) } label: {
|
||||
Image(systemName: "shuffle").font(.title3.weight(.semibold))
|
||||
.frame(width: 54, height: 54).background(.thinMaterial, in: Circle())
|
||||
ZStack {
|
||||
artistPageBackdrop(artist)
|
||||
|
||||
ScrollView {
|
||||
VStack(alignment: .leading, spacing: 14) {
|
||||
artistHero(artist)
|
||||
|
||||
HStack {
|
||||
Text("Top Songs").font(.title2.weight(.bold))
|
||||
Spacer()
|
||||
NavigationLink {
|
||||
ArtistSongsView(artistID: artist.id, artistName: artist.name)
|
||||
} label: {
|
||||
Image(systemName: "chevron.right")
|
||||
.font(.headline.weight(.semibold))
|
||||
}
|
||||
.buttonStyle(.plain).disabled(viewModel.tracks.isEmpty)
|
||||
.accessibilityLabel("Shuffle \(artist.name)")
|
||||
Button { player.play(viewModel.tracks) } label: {
|
||||
Label("Play", systemImage: "play.fill").font(.title3.weight(.semibold))
|
||||
.frame(maxWidth: .infinity).frame(height: 54).foregroundStyle(.white)
|
||||
.background(.red, in: Capsule())
|
||||
}
|
||||
.buttonStyle(.plain).disabled(viewModel.tracks.isEmpty)
|
||||
.accessibilityLabel("Play \(artist.name)")
|
||||
.accessibilityLabel("See all songs by \(artist.name)")
|
||||
}
|
||||
.padding(.top, 4)
|
||||
}
|
||||
Divider()
|
||||
HStack {
|
||||
Text("Tracks").font(.title2.weight(.bold))
|
||||
Spacer()
|
||||
NavigationLink("See All") { ArtistSongsView(artistID: artist.id, artistName: artist.name) }
|
||||
.font(.subheadline.weight(.semibold))
|
||||
}
|
||||
if let error = viewModel.errorMessage {
|
||||
retryBlock(title: "Couldn't Load Artist Content", message: error)
|
||||
} else if viewModel.isLoading && viewModel.tracks.isEmpty {
|
||||
ProgressView().frame(maxWidth: .infinity).padding(.vertical, 20)
|
||||
} else if viewModel.tracks.isEmpty {
|
||||
ContentUnavailableView("No Songs", systemImage: "music.note.list",
|
||||
description: Text("This artist doesn't have any songs yet."))
|
||||
} else {
|
||||
LazyVStack(spacing: 0) {
|
||||
ForEach(viewModel.tracks.indices, id: \.self) { index in
|
||||
TrackRowView(track: viewModel.tracks[index], index: index) {
|
||||
player.play(viewModel.tracks, startingAt: index)
|
||||
}
|
||||
if index < viewModel.tracks.count - 1 {
|
||||
Divider().padding(.leading, 42)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
VStack(alignment: .leading, spacing: 12) {
|
||||
Text("Albums").font(.title2.weight(.bold))
|
||||
if viewModel.albums.isEmpty && !viewModel.isLoading {
|
||||
Text("No albums available.").foregroundStyle(.secondary)
|
||||
.padding(.horizontal, 20)
|
||||
if let error = viewModel.errorMessage {
|
||||
retryBlock(title: "Couldn't Load Artist Content", message: error)
|
||||
} else if viewModel.isLoading && viewModel.tracks.isEmpty {
|
||||
ProgressView().frame(maxWidth: .infinity).padding(.vertical, 20)
|
||||
} else if viewModel.tracks.isEmpty {
|
||||
ContentUnavailableView("No Songs", systemImage: "music.note.list",
|
||||
description: Text("This artist doesn't have any songs yet."))
|
||||
} else {
|
||||
ScrollView(.horizontal) {
|
||||
LazyHStack(alignment: .top, spacing: 14) {
|
||||
ForEach(viewModel.albums) { album in
|
||||
NavigationLink { AlbumDetailView(albumID: album.id) } label: {
|
||||
VStack(alignment: .leading, spacing: 6) {
|
||||
AlbumArtworkView(url: viewModel.artworkURL(for: album))
|
||||
Text(album.name).font(.subheadline.weight(.medium))
|
||||
.lineLimit(2).foregroundStyle(.primary)
|
||||
}
|
||||
.containerRelativeFrame(.horizontal) { length, _ in (length - 40 - 28) / 2.2 }
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
LazyVStack(spacing: 0) {
|
||||
ForEach(0..<min(viewModel.tracks.count, 3), id: \.self) { index in
|
||||
let track = viewModel.tracks[index]
|
||||
artistTrackRow(track, index: index)
|
||||
if index < min(viewModel.tracks.count, 3) - 1 {
|
||||
Divider().padding(.leading, 68)
|
||||
}
|
||||
}
|
||||
.scrollTargetLayout()
|
||||
}
|
||||
.scrollIndicators(.hidden).scrollTargetBehavior(.viewAligned)
|
||||
}
|
||||
|
||||
if !viewModel.albums.isEmpty {
|
||||
VStack(alignment: .leading, spacing: 12) {
|
||||
Text("Albums").font(.title2.weight(.bold))
|
||||
.padding(.horizontal, 20)
|
||||
ScrollView(.horizontal) {
|
||||
LazyHStack(alignment: .top, spacing: 14) {
|
||||
ForEach(viewModel.albums) { album in
|
||||
NavigationLink { AlbumDetailView(albumID: album.id) } label: {
|
||||
VStack(alignment: .leading, spacing: 6) {
|
||||
AlbumArtworkView(url: viewModel.artworkURL(for: album))
|
||||
Text(album.name).font(.subheadline.weight(.medium))
|
||||
.lineLimit(2).foregroundStyle(.primary)
|
||||
}
|
||||
.containerRelativeFrame(.horizontal) { length, _ in (length - 40 - 28) / 2.5 }
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
}
|
||||
.scrollTargetLayout()
|
||||
}
|
||||
.contentMargins(.horizontal, 20)
|
||||
.scrollIndicators(.hidden).scrollTargetBehavior(.viewAligned)
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding(.bottom, 24)
|
||||
}
|
||||
.scrollIndicators(.hidden)
|
||||
.ignoresSafeArea(edges: .top)
|
||||
.refreshable { await viewModel.load(forceRefresh: true) }
|
||||
.onScrollGeometryChange(for: CGFloat.self) { $0.contentOffset.y } action: { old, new in
|
||||
if new > old + 2 { player.compactMiniPlayerForDownwardScroll() }
|
||||
}
|
||||
.padding(.horizontal, 20).padding(.top, 16).padding(.bottom, 24)
|
||||
}
|
||||
.scrollIndicators(.hidden)
|
||||
.refreshable { await viewModel.load(forceRefresh: true) }
|
||||
.onScrollGeometryChange(for: CGFloat.self) { $0.contentOffset.y } action: { old, new in
|
||||
if new > old + 2 { player.compactMiniPlayerForDownwardScroll() }
|
||||
}
|
||||
|
||||
private func artistPageBackdrop(_ artist: Artist) -> some View {
|
||||
GeometryReader { geometry in
|
||||
ZStack {
|
||||
Color.black
|
||||
if let url = viewModel.artworkURL(for: artist) {
|
||||
AsyncImage(url: url) { phase in
|
||||
if let image = phase.image {
|
||||
image.resizable().scaledToFill()
|
||||
} else {
|
||||
Color.black
|
||||
}
|
||||
}
|
||||
.frame(width: geometry.size.width, height: geometry.size.height)
|
||||
.blur(radius: 48)
|
||||
.opacity(0.90)
|
||||
.clipped()
|
||||
}
|
||||
LinearGradient(
|
||||
colors: [.black.opacity(0.04), .black.opacity(0.18)],
|
||||
startPoint: .top,
|
||||
endPoint: .bottom
|
||||
)
|
||||
}
|
||||
.frame(width: geometry.size.width, height: geometry.size.height)
|
||||
}
|
||||
.ignoresSafeArea()
|
||||
}
|
||||
|
||||
private func artistHero(_ artist: Artist) -> some View {
|
||||
ZStack(alignment: .bottom) {
|
||||
AsyncImage(url: viewModel.artworkURL(for: artist)) { phase in
|
||||
if let image = phase.image {
|
||||
image.resizable().scaledToFill()
|
||||
} else {
|
||||
Rectangle().fill(.quaternary)
|
||||
.overlay { Image(systemName: "music.mic").font(.system(size: 56)).foregroundStyle(.secondary) }
|
||||
}
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
.containerRelativeFrame(.vertical) { length, _ in min(length * 0.43, 440) }
|
||||
.clipped()
|
||||
.overlay {
|
||||
LinearGradient(stops: [
|
||||
.init(color: .black.opacity(0.22), location: 0),
|
||||
.init(color: .clear, location: 0.34),
|
||||
.init(color: .black.opacity(0.04), location: 0.62),
|
||||
.init(color: .black.opacity(0.14), location: 1),
|
||||
], startPoint: .top, endPoint: .bottom)
|
||||
}
|
||||
.accessibilityLabel("\(artist.name) artist artwork")
|
||||
|
||||
VStack(spacing: 18) {
|
||||
Text(artist.name)
|
||||
.font(.system(size: 32, weight: .bold))
|
||||
.multilineTextAlignment(.center)
|
||||
.foregroundStyle(.white)
|
||||
.shadow(color: .black.opacity(0.22), radius: 8, y: 2)
|
||||
|
||||
HStack(spacing: 18) {
|
||||
NavigationLink {
|
||||
ArtistSongsView(artistID: artist.id, artistName: artist.name)
|
||||
} label: {
|
||||
Image(systemName: "info.circle.fill")
|
||||
.font(.title2.weight(.medium))
|
||||
.foregroundStyle(.white.opacity(0.9))
|
||||
.frame(width: 54, height: 54)
|
||||
.background(.ultraThinMaterial.opacity(0.8), in: Circle())
|
||||
}
|
||||
.accessibilityLabel("Songs by \(artist.name)")
|
||||
|
||||
Button { player.play(viewModel.tracks) } label: {
|
||||
Image(systemName: "play.fill")
|
||||
.font(.system(size: 32, weight: .semibold))
|
||||
.foregroundStyle(.black.opacity(0.55))
|
||||
.frame(width: 84, height: 84)
|
||||
.background(.white, in: Circle())
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.disabled(viewModel.tracks.isEmpty)
|
||||
.accessibilityLabel("Play \(artist.name)")
|
||||
|
||||
Button { player.play(viewModel.tracks, shuffled: true) } label: {
|
||||
Image(systemName: "shuffle")
|
||||
.font(.title2.weight(.medium))
|
||||
.foregroundStyle(.white)
|
||||
.frame(width: 54, height: 54)
|
||||
.background(.ultraThinMaterial.opacity(0.8), in: Circle())
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.disabled(viewModel.tracks.isEmpty)
|
||||
.accessibilityLabel("Shuffle \(artist.name)")
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, 20)
|
||||
.padding(.bottom, 18)
|
||||
|
||||
HStack(spacing: 0) {
|
||||
Button { dismiss() } label: {
|
||||
Image(systemName: "chevron.left")
|
||||
.font(.title3.weight(.semibold))
|
||||
.foregroundStyle(.white)
|
||||
.frame(width: 52, height: 52)
|
||||
.background(.ultraThinMaterial.opacity(0.8), in: Circle())
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.accessibilityLabel("Back")
|
||||
|
||||
Spacer()
|
||||
|
||||
HStack(spacing: 20) {
|
||||
ShareLink(item: URL(string: "https://music.lucasskt.dk/artist/\(artist.id)")!) {
|
||||
Image(systemName: "square.and.arrow.up")
|
||||
.font(.title3.weight(.medium))
|
||||
.foregroundStyle(.white)
|
||||
}
|
||||
.accessibilityLabel("Share \(artist.name)")
|
||||
|
||||
Menu {
|
||||
Button("Play", systemImage: "play.fill") {
|
||||
player.play(viewModel.tracks)
|
||||
}
|
||||
Button("Shuffle", systemImage: "shuffle") {
|
||||
player.play(viewModel.tracks, shuffled: true)
|
||||
}
|
||||
} label: {
|
||||
Image(systemName: "ellipsis")
|
||||
.font(.title3.weight(.semibold))
|
||||
.foregroundStyle(.white)
|
||||
}
|
||||
.accessibilityLabel("More options for \(artist.name)")
|
||||
}
|
||||
.padding(.horizontal, 22)
|
||||
.frame(height: 52)
|
||||
.background(.ultraThinMaterial.opacity(0.8), in: Capsule())
|
||||
}
|
||||
.padding(.horizontal, 18)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top)
|
||||
.padding(.top, 58)
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
}
|
||||
|
||||
private func artistTrackRow(_ track: Track, index: Int) -> some View {
|
||||
Button { player.play(viewModel.tracks, startingAt: index) } label: {
|
||||
HStack(spacing: 14) {
|
||||
trackArtwork(track)
|
||||
.frame(width: 48, height: 48)
|
||||
.clipShape(RoundedRectangle(cornerRadius: 9, style: .continuous))
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text(track.name).font(.body.weight(.medium)).foregroundStyle(.primary).lineLimit(1)
|
||||
Text(albumName(for: track)).font(.subheadline).foregroundStyle(.secondary).lineLimit(1)
|
||||
}
|
||||
Spacer(minLength: 8)
|
||||
Image(systemName: "ellipsis").font(.body.weight(.semibold)).foregroundStyle(.secondary)
|
||||
}
|
||||
.padding(.vertical, 6)
|
||||
.contentShape(Rectangle())
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.padding(.horizontal, 20)
|
||||
.accessibilityLabel("Play \(track.name), \(albumName(for: track))")
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private func trackArtwork(_ track: Track) -> some View {
|
||||
if let url = viewModel.artworkURL(for: track) {
|
||||
AsyncImage(url: url) { phase in
|
||||
if let image = phase.image { image.resizable().scaledToFill() }
|
||||
else { artworkPlaceholder }
|
||||
}
|
||||
} else {
|
||||
artworkPlaceholder
|
||||
}
|
||||
}
|
||||
|
||||
private var artworkPlaceholder: some View {
|
||||
Image(systemName: "music.note")
|
||||
.foregroundStyle(.secondary)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
.background(.quaternary)
|
||||
}
|
||||
|
||||
private func albumName(for track: Track) -> String {
|
||||
guard case .value(let album) = track.album else { return "Song" }
|
||||
return album.name
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
|
||||
Reference in new issue
Block a user