-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathActiveRunView.swift
More file actions
85 lines (71 loc) · 2.33 KB
/
Copy pathActiveRunView.swift
File metadata and controls
85 lines (71 loc) · 2.33 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
import SwiftUI
struct ActiveRunView: View {
@EnvironmentObject var runManager: RunManager
var body: some View {
VStack(spacing: 0) {
Spacer()
// Timer
Text(runManager.formattedElapsed)
.font(.system(size: 72, weight: .thin, design: .monospaced))
.monospacedDigit()
Text("duration")
.font(.caption)
.foregroundStyle(.secondary)
.padding(.bottom, 40)
// Distance
Text(runManager.formattedDistance)
.font(.system(size: 40, weight: .light, design: .monospaced))
.monospacedDigit()
Text("distance")
.font(.caption)
.foregroundStyle(.secondary)
.padding(.bottom, 32)
// Pace
Text(runManager.formattedPace)
.font(.system(size: 40, weight: .light, design: .monospaced))
.monospacedDigit()
Text("min/mile")
.font(.caption)
.foregroundStyle(.secondary)
Spacer()
// Controls
controls
.padding(.bottom, 48)
}
.navigationBarHidden(true)
}
@ViewBuilder
private var controls: some View {
switch runManager.state {
case .idle:
Button(action: runManager.start) {
label("Start", color: .green)
}
case .active:
HStack(spacing: 32) {
Button(action: runManager.pause) {
label("Pause", color: .orange)
}
Button(action: runManager.stop) {
label("Stop", color: .red)
}
}
case .paused:
HStack(spacing: 32) {
Button(action: runManager.resume) {
label("Resume", color: .green)
}
Button(action: runManager.stop) {
label("Save", color: .blue)
}
}
}
}
private func label(_ text: String, color: Color) -> some View {
Text(text)
.font(.title2.weight(.semibold))
.foregroundStyle(.white)
.frame(width: 120, height: 120)
.background(color, in: Circle())
}
}