Repository navigation
Expand file tree
/
Copy pathAlbumItem.swift
More file actions
66 lines (56 loc) · 1.7 KB
/
Copy pathAlbumItem.swift
File metadata and controls
66 lines (56 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
See the LICENSE.txt file for this sample’s licensing information.
Abstract:
A row in the album grid.
*/
import AppIntents
import SwiftUI
struct AlbumItem: View, Sendable {
// MARK: Properties
let album: Album
@State private var image: Image?
// MARK: Lifecycle
var body: some View {
GeometryReader { proxy in
ZStack(alignment: .topLeading) {
if let image {
image
.resizable()
.blur(radius: 4)
} else {
Rectangle()
}
HStack(alignment: .top) {
Text(album.title)
.font(.title)
.multilineTextAlignment(.leading)
.bold()
Spacer()
Text(album.assets.count.description)
.font(.title)
.opacity(0.75)
}
.foregroundColor(.white)
.padding()
}
.cornerRadius(10)
.padding(.horizontal)
.onAppear {
let targetSize = proxy.size
Task.detached {
try await album.fetchAssets()
guard let asset = album.assets.first else {
return
}
let image = await ImageManager.shared.requestImage(for: asset, targetSize: targetSize)
await MainActor.run {
self.image = image
}
}
}
}
.frame(height: 200)
.id(album)
.tag(album)
}
}