Skip to content

Commit 4d508f6

Browse files
committed
automatic progress in preview
1 parent 1f5ecd1 commit 4d508f6

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

Examples/DemosApp/DemosApp/ComponentsPreview/PreviewPages/ProgressBarPreview.swift

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@ import UIKit
44

55
struct ProgressBarPreview: View {
66
@State private var model = ProgressBarVM()
7-
@State private var currentValue: CGFloat = 75
7+
@State private var currentValue: CGFloat = 0
8+
private let timer = Timer
9+
.publish(every: 0.1, on: .main, in: .common)
10+
.autoconnect()
811

912
var body: some View {
1013
VStack {
1114
PreviewWrapper(title: "SwiftUI") {
12-
SUProgressBar(currentValue: $currentValue, model: model)
15+
SUProgressBar(currentValue: $currentValue, model: self.model)
1316
}
1417
Form {
1518
ComponentColorPicker(selection: self.$model.color)
16-
Stepper("Current Value", value: $currentValue, in: self.model.minValue...self.model.maxValue, step: 10)
1719
CornerRadiusPicker(selection: self.$model.cornerRadius) {
1820
Text("Custom: 2px").tag(ComponentRadius.custom(2))
1921
}
@@ -25,6 +27,13 @@ struct ProgressBarPreview: View {
2527
}
2628
}
2729
}
30+
.onReceive(timer) { _ in
31+
if self.currentValue < self.model.maxValue {
32+
self.currentValue += 1
33+
} else {
34+
self.currentValue = 0
35+
}
36+
}
2837
}
2938
}
3039

0 commit comments

Comments
 (0)