/
InfoAsset.swift
54 lines (50 loc) · 1.63 KB
/
InfoAsset.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
import SwiftUI
/**
Data Decoded by Player for `InfoAsset`
*/
struct InfoData: AssetData {
/// The ID of the asset
var id: String
/// The Type of the asset
var type: String
/// An asset to use as a title for this asset
var title: WrappedAsset?
/// An asset to use as a subTitle for this asset
var subTitle: WrappedAsset?
/// An asset to use as the primary slot for info
var primaryInfo: WrappedAsset?
/// Assets to use as actions in this asset
var actions: [WrappedAsset]?
/// An asset to use as a footer for this asset
var footer: WrappedAsset?
}
/**
Wrapper class to tie `InfoData` to a SwiftUI `View`
*/
class InfoAsset: UncontrolledAsset<InfoData> {
/// A type erased view object
override var view: AnyView { AnyView(InfoAssetView(model: model)) }
}
/**
View implementation for `InfoAsset`
*/
struct InfoAssetView: View {
/// The viewModel with decoded data, supplied by `InfoAsset`
@ObservedObject var model: AssetViewModel<InfoData>
@ViewBuilder
var body: some View {
VStack {
model.data.title?.asset?.view.font(.title).padding(.bottom, 40)
model.data.subTitle?.asset?.view.font(.subheadline).padding(.bottom, 40)
model.data.primaryInfo?.asset?.view
if let actions = model.data.actions?.compactMap { $0.asset } {
ForEach(actions) { action in
action.view
}
}
model.data.footer?.asset?.view.font(.subheadline).padding(.top, 12)
}
.accessibilityElement(children: .contain)
.accessibility(identifier: model.data.id)
}
}