forked from LoopKit/LoopKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgressView.swift
More file actions
69 lines (55 loc) · 1.69 KB
/
ProgressView.swift
File metadata and controls
69 lines (55 loc) · 1.69 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
//
// ProgressView.swift
// DashKitUI
//
// Created by Pete Schwamb on 3/2/20.
// Copyright © 2020 LoopKit Authors. All rights reserved.
//
import SwiftUI
// TODO: SwiftUI now has built in ProgressView to replace this
public struct ProgressView: View {
private let progress: CGFloat
private let barHeight: CGFloat = 8
public init(progress: CGFloat) {
self.progress = progress
}
public var body: some View {
return GeometryReader { geometry in
ZStack(alignment: .leading) {
Rectangle()
.opacity(0.1)
.cornerRadius(self.barHeight/2)
.animation(nil)
Rectangle()
.foregroundColor(Color.accentColor)
.frame(width: geometry.size.width * self.progress)
.cornerRadius(self.barHeight/2)
}
}
.frame(height: barHeight)
}
}
struct ProgressTestView: View {
@State var showDetail: Bool = false
@State var madeProgress: Bool = false
var body: some View {
VStack {
ProgressView(progress: madeProgress ? 0.9 : 0.5)
.animation(.linear(duration: 2))
.padding()
.opacity(showDetail ? 1 : 0)
.animation(.linear(duration: 0.2))
Button("Test") {
self.showDetail.toggle()
self.madeProgress.toggle()
}
}
.animation(.linear(duration: 0.2))
}
}
struct ProgressView_Previews: PreviewProvider {
@State var showDetail: Bool = false
static var previews: some View {
ProgressTestView()
}
}