Reuse shared album cards across screens
This commit is contained in:
1 parent
85e3b3148e
commit
dd733e8e03
5 files changed
+67
-93
No files matched your search
@@ -0,0 +1,56 @@
|
||||
import SwiftUI
|
||||
|
||||
struct AlbumCardView: View {
|
||||
let album: Album
|
||||
let artworkURL: URL?
|
||||
var showsArtists = true
|
||||
|
||||
private var artistNames: String {
|
||||
album.artists.compactMap { reference in
|
||||
guard case .value(let artist) = reference else { return nil }
|
||||
return artist.name
|
||||
}
|
||||
.joined(separator: ", ")
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 5) {
|
||||
AlbumArtworkView(url: artworkURL)
|
||||
.frame(maxWidth: .infinity)
|
||||
.aspectRatio(1, contentMode: .fit)
|
||||
|
||||
Text(album.name)
|
||||
.font(.subheadline.weight(.medium))
|
||||
.lineLimit(1)
|
||||
.truncationMode(.tail)
|
||||
.foregroundStyle(.primary)
|
||||
|
||||
if showsArtists && !artistNames.isEmpty {
|
||||
Text(artistNames)
|
||||
.font(.footnote)
|
||||
.lineLimit(1)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
}
|
||||
.frame(maxWidth: .infinity, alignment: .topLeading)
|
||||
.accessibilityElement(children: .combine)
|
||||
}
|
||||
}
|
||||
|
||||
struct AlbumCardView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
AlbumCardView(
|
||||
album: Album(
|
||||
id: "album-preview",
|
||||
name: "An Album with a Long Title",
|
||||
artists: [.value(Artist(id: "artist-preview", name: "Example Artist", file: nil))],
|
||||
file: nil,
|
||||
genre: nil
|
||||
),
|
||||
artworkURL: nil
|
||||
)
|
||||
.frame(width: 170)
|
||||
.padding()
|
||||
.preferredColorScheme(.dark)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user