-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathScanView.swift
More file actions
157 lines (137 loc) · 4.63 KB
/
Copy pathScanView.swift
File metadata and controls
157 lines (137 loc) · 4.63 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
//
// ScanView.swift
// NativeAppTemplate
//
import CoreNFC
import SwiftUI
enum ScanType: String {
case completeScan
case test
var displayString: String {
switch self {
case .completeScan:
"Complete Scan"
case .test:
"Test"
}
}
}
// MARK: - CaseIterable
extension ScanType: CaseIterable {
var index: Self.AllCases.Index {
get {
Self.allCases.firstIndex(of: self)!
}
set {
self = Self.allCases[newValue]
}
}
var count: Int {
Self.allCases.count
}
}
// MARK: - Identifiable
extension ScanType: Identifiable {
var id: Self {
self
}
}
struct ScanView: View {
@Environment(\.sessionController) private var sessionController: SessionControllerProtocol
@StateObject private var nfcManager = appSingletons.nfcManager
@State private var viewModel: ScanViewModel
init(viewModel: ScanViewModel) {
_viewModel = State(initialValue: viewModel)
}
var body: some View {
contentView
.onChange(of: sessionController.didBackgroundTagReading) {
viewModel.handleBackgroundTagReading()
}
}
}
// MARK: - private
private extension ScanView {
var contentView: some View {
@ViewBuilder var contentView: some View {
if viewModel.isBusy {
LoadingView()
} else {
scanView
.onChange(of: nfcManager.isScanResultChanged) {
viewModel.handleScanResultChanged()
}
.onChange(of: nfcManager.isScanResultChangedForTesting) {
viewModel.handleScanResultChangedForTesting()
}
}
}
return contentView
}
var scanView: some View {
ScrollView {
VStack(spacing: NativeAppTemplateConstants.Spacing.xxl) {
switch viewModel.scanType {
case .completeScan:
if !viewModel.isShowingResetConfirmationDialog {
GroupBox(label: Label(String.completeScan, systemImage: "flag.checkered")) {
MainButtonView(title: String.scan, type: .coloredPrimary(withArrow: false)) {
viewModel.startCompleteScan()
}
.padding()
Text(String.completeScanHelp)
.font(.uiFootnote)
.foregroundStyle(.contentText)
}
.foregroundStyle(.accent)
.backgroundStyle(.ultraThinMaterial)
}
CompleteScanResultView(
completeScanResult: sessionController.completeScanResult
)
case .test:
GroupBox(label: Label(String.showTagInfoScan, systemImage: "info.circle")) {
MainButtonView(title: String.scan, type: .coloredSecondary(withArrow: false)) {
viewModel.startTestScan()
}
.padding()
Text(String.showTagInfoScanHelp)
.font(.uiFootnote)
.foregroundStyle(.contentText)
}
.foregroundStyle(.contentText)
.backgroundStyle(.ultraThinMaterial)
ShowTagInfoScanResultView(
showTagInfoScanResult: sessionController.showTagInfoScanResult
)
}
Spacer()
}
}
.toolbar {
ToolbarItem(placement: .principal) {
Picker(String("ScanType"), selection: $viewModel.scanType) {
Text(String.completeScan).tag(ScanType.completeScan)
Text(String.showTagInfoScan).tag(ScanType.test)
}
.pickerStyle(SegmentedPickerStyle())
}
}
.padding()
.alert(
String.itemTagAlreadyCompleted,
isPresented: $viewModel.isShowingResetConfirmationDialog
) {
Button(String.reset, role: .destructive) {
viewModel.resetTag()
}
Button(String.cancel, role: .cancel) {
viewModel.dismissResetConfirmationDialog()
}
} message: {
Text(String.areYouSure)
}
.accessibility(identifier: "scanView")
.scrollContentBackground(.hidden)
}
}