Repository navigation
Expand file tree
/
Copy pathSwiftUIDashboardSample.swift
More file actions
196 lines (170 loc) · 5.87 KB
/
Copy pathSwiftUIDashboardSample.swift
File metadata and controls
196 lines (170 loc) · 5.87 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
//
// SwiftUIDashboardSample.swift
// Trip Identifier Portfolio Samples
//
// This non-sensitive excerpt demonstrates a SwiftUI dashboard structure with
// state-driven UI, mode switching, and reusable cards. The values are demo
// placeholders and do not include production scoring or earnings formulas.
//
import SwiftUI
struct DashboardState {
var isTargetModeEnabled: Bool
var isShiftRunning: Bool
var currentNetText: String
var shiftTimeText: String
var latestRecommendation: RecommendationSummary
static let demo = DashboardState(
isTargetModeEnabled: true,
isShiftRunning: true,
currentNetText: "$117.60",
shiftTimeText: "04:12:36",
latestRecommendation: RecommendationSummary(
title: "Recommended",
subtitle: "Good pace for this shift",
takeHomeText: "$18.60",
hourlyText: "$31/hr",
tint: .green
)
)
}
struct RecommendationSummary {
var title: String
var subtitle: String
var takeHomeText: String
var hourlyText: String
var tint: Color
}
struct DriverDashboardSampleView: View {
@State private var state = DashboardState.demo
var body: some View {
NavigationStack {
VStack(spacing: 12) {
latestOfferCard
modeSwitcher
netIncomeCard
shiftTimerCard
Spacer()
}
.padding()
.background(Color(.systemGroupedBackground))
.navigationTitle("Trip Identifier")
}
}
private var latestOfferCard: some View {
Card {
HStack(alignment: .top) {
VStack(alignment: .leading, spacing: 8) {
Text("Latest Offer")
.font(.caption.weight(.semibold))
.foregroundStyle(.secondary)
Text(state.latestRecommendation.title)
.font(.largeTitle.weight(.black))
.foregroundStyle(state.latestRecommendation.tint)
Text(state.latestRecommendation.subtitle)
.font(.subheadline.weight(.semibold))
.foregroundStyle(.secondary)
Text(state.latestRecommendation.takeHomeText)
.font(.system(size: 48, weight: .black, design: .rounded))
.monospacedDigit()
}
Spacer()
VStack(spacing: 10) {
MetricTile(title: "Hourly", value: state.latestRecommendation.hourlyText)
MetricTile(title: "Time", value: "26 min")
}
}
}
}
private var modeSwitcher: some View {
HStack(spacing: 10) {
ModeButton(
title: "Basic Mode",
isSelected: !state.isTargetModeEnabled
) {
state.isTargetModeEnabled = false
}
ModeButton(
title: "Target Mode",
isSelected: state.isTargetModeEnabled
) {
state.isTargetModeEnabled = true
}
}
}
private var netIncomeCard: some View {
Card {
VStack(alignment: .leading, spacing: 8) {
Text(state.isTargetModeEnabled ? "Shift Net Income" : "Current Estimated Net")
.font(.headline)
Text(state.currentNetText)
.font(.system(size: 46, weight: .black, design: .rounded))
.monospacedDigit()
if state.isTargetModeEnabled {
ProgressView(value: 0.78)
.tint(.green)
}
}
}
}
private var shiftTimerCard: some View {
Card {
HStack {
VStack(alignment: .leading) {
Text(state.shiftTimeText)
.font(.system(size: 38, weight: .black, design: .monospaced))
Text(state.isShiftRunning ? "Online" : "Paused")
.font(.subheadline.weight(.semibold))
.foregroundStyle(state.isShiftRunning ? .green : .secondary)
}
Spacer()
Button(state.isShiftRunning ? "Pause" : "Go Online") {
state.isShiftRunning.toggle()
}
.buttonStyle(.borderedProminent)
}
}
}
}
private struct Card<Content: View>: View {
@ViewBuilder var content: Content
var body: some View {
content
.padding(16)
.frame(maxWidth: .infinity, alignment: .leading)
.background(Color(.secondarySystemGroupedBackground))
.clipShape(RoundedRectangle(cornerRadius: 20, style: .continuous))
}
}
private struct MetricTile: View {
let title: String
let value: String
var body: some View {
VStack(spacing: 4) {
Text(title)
.font(.caption.weight(.semibold))
.foregroundStyle(.secondary)
Text(value)
.font(.headline.monospacedDigit().weight(.bold))
}
.frame(width: 92, height: 68)
.background(Color(.tertiarySystemGroupedBackground))
.clipShape(RoundedRectangle(cornerRadius: 14, style: .continuous))
}
}
private struct ModeButton: View {
let title: String
let isSelected: Bool
let action: () -> Void
var body: some View {
Button(action: action) {
Text(title)
.font(.subheadline.weight(.bold))
.frame(maxWidth: .infinity)
.padding(.vertical, 12)
}
.buttonStyle(.plain)
.foregroundStyle(isSelected ? .white : .primary)
.background(isSelected ? Color.green : Color(.secondarySystemGroupedBackground))
.clipShape(Capsule())
}
}