/
CollectionAsset.swift
41 lines (37 loc) · 1.05 KB
/
CollectionAsset.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
import SwiftUI
import Combine
/**
Data Decoded by Player for `CollectionAsset`
*/
struct CollectionData: AssetData {
/// The ID of the asset
var id: String
/// The Type of the asset
var type: String
/// The assets to be rendered in this collection
var values: [WrappedAsset?]
}
/**
Wrapper class to tie `CollectionData` to a SwiftUI `View`
*/
final class CollectionAsset: UncontrolledAsset<CollectionData> {
/// A type erased view object
public override var view: AnyView { AnyView(CollectionAssetView(model: model)) }
}
/**
View implementation for `CollectionAsset`
*/
struct CollectionAssetView: View {
/// The viewModel with decoded data, supplied by `CollectionAsset`
@ObservedObject var model: AssetViewModel<CollectionData>
@ViewBuilder
var body: some View {
VStack {
ForEach(model.data.values.compactMap({ $0?.asset })) { asset in
asset.view
}
}
.accessibilityElement(children: .contain)
.accessibility(identifier: model.data.id)
}
}