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
@@ -85,7 +85,8 @@ private struct HomeAlbumCarousel: View {
|
||||
NavigationLink {
|
||||
AlbumDetailView(albumID: album.id)
|
||||
} label: {
|
||||
HomeAlbumCard(album: album, artworkURL: artworkURL(album))
|
||||
AlbumCardView(album: album, artworkURL: artworkURL(album))
|
||||
.frame(maxWidth: 150)
|
||||
.containerRelativeFrame(.horizontal) { length, _ in
|
||||
(length - 40 - 28) / 2.2
|
||||
}
|
||||
@@ -112,51 +113,6 @@ private struct HomeAlbumCarousel_Previews: PreviewProvider {
|
||||
}
|
||||
}
|
||||
|
||||
private struct HomeAlbumCard: View {
|
||||
let album: Album
|
||||
let artworkURL: URL?
|
||||
|
||||
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: 150)
|
||||
|
||||
Text(album.name)
|
||||
.font(.subheadline.weight(.medium))
|
||||
.lineLimit(2)
|
||||
.foregroundStyle(.primary)
|
||||
|
||||
if !artistNames.isEmpty {
|
||||
Text(artistNames)
|
||||
.font(.footnote)
|
||||
.lineLimit(1)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
}
|
||||
.accessibilityElement(children: .combine)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private struct HomeAlbumCard_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
HomeAlbumCard(
|
||||
album: HomeViewModel.preview.sections[0].albums[0],
|
||||
artworkURL: nil
|
||||
)
|
||||
.padding()
|
||||
.frame(maxWidth: 240)
|
||||
}
|
||||
}
|
||||
|
||||
struct HomeView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
HomeView(viewModel: .preview)
|
||||
|
||||
Reference in new issue
Block a user