-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAssetItem.swift
77 lines (59 loc) · 1.72 KB
/
AssetItem.swift
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
67
68
69
70
71
72
73
74
75
76
77
/*
See the LICENSE.txt file for this sample’s licensing information.
Abstract:
The view for a single media asset.
*/
import AppIntents
import SwiftUI
struct AssetView: View, Sendable {
// MARK: Properties
let asset: Asset
private let targetSize = CGSize(width: 100, height: 100)
@State private var image: Image?
// MARK: Lifecycle
var body: some View {
Group {
if let image {
ThumbnailView(image: image, type: asset.type, isFavorite: asset.isFavorite)
} else {
ProgressView()
.padding()
}
}
.onAppear {
Task.detached {
let image = await ImageManager.shared.requestImage(for: asset, targetSize: targetSize)
await MainActor.run {
self.image = image
}
try? await asset.fetchPlacemark()
}
}
.id(asset)
.tag(asset)
}
// MARK: Layout
struct ThumbnailView: View {
// MARK: Properties
let image: Image
let type: AssetType
let isFavorite: Bool
// MARK: Lifecycle
var body: some View {
ZStack(alignment: .bottomTrailing) {
ZStack(alignment: .center) {
image
if type == .video {
Image(systemName: "video.fill")
.font(.title)
.foregroundColor(.white)
.shadow(radius: 4)
}
}
FavoriteView(isFavorite: isFavorite)
}
.clipped()
.cornerRadius(10)
}
}
}