@@ -4,11 +4,8 @@ import UIKit
4
4
5
5
struct CircularProgressPreview : View {
6
6
@State private var model = Self . initialModel
7
- @State private var currentValue : CGFloat = Self . initialValue
8
7
9
- private let circularProgress = UKCircularProgress (
10
- model: Self . initialModel
11
- )
8
+ private let circularProgress = UKCircularProgress ( model: Self . initialModel)
12
9
13
10
private let timer = Timer
14
11
. publish ( every: 0.5 , on: . main, in: . common)
@@ -20,58 +17,54 @@ struct CircularProgressPreview: View {
20
17
self . circularProgress
21
18
. preview
22
19
. onAppear {
23
- self . circularProgress. currentValue = Self . initialValue
24
20
self . circularProgress. model = Self . initialModel
25
21
}
26
22
. onChange ( of: model) { newModel in
27
23
self . circularProgress. model = newModel
28
24
}
29
- . onChange ( of: self . currentValue) { newValue in
30
- self . circularProgress. currentValue = newValue
31
- }
32
25
}
33
26
PreviewWrapper ( title: " SwiftUI " ) {
34
- SUCircularProgress ( currentValue : self . currentValue , model: self . model)
27
+ SUCircularProgress ( model: self . model)
35
28
}
36
29
Form {
37
30
ComponentColorPicker ( selection: self . $model. color)
38
31
CaptionFontPicker ( selection: self . $model. font)
32
+ Picker ( " Line Cap " , selection: self . $model. lineCap) {
33
+ Text ( " Rounded " ) . tag ( CircularProgressVM . LineCap. rounded)
34
+ Text ( " Square " ) . tag ( CircularProgressVM . LineCap. square)
35
+ }
39
36
Picker ( " Line Width " , selection: self . $model. lineWidth) {
40
37
Text ( " Default " ) . tag ( Optional< CGFloat> . none)
41
38
Text ( " 2 " ) . tag ( Optional< CGFloat> . some( 2 ) )
42
39
Text ( " 4 " ) . tag ( Optional< CGFloat> . some( 4 ) )
43
40
Text ( " 8 " ) . tag ( Optional< CGFloat> . some( 8 ) )
44
41
}
45
- SizePicker ( selection: self . $model. size)
46
- Picker ( " Style " , selection: self . $model. style) {
47
- Text ( " Light " ) . tag ( CircularProgressVM . Style. light)
48
- Text ( " Striped " ) . tag ( CircularProgressVM . Style. striped)
42
+ Picker ( " Shape " , selection: self . $model. shape) {
43
+ Text ( " Circle " ) . tag ( CircularProgressVM . Shape. circle)
44
+ Text ( " Arc " ) . tag ( CircularProgressVM . Shape. arc)
49
45
}
46
+ SizePicker ( selection: self . $model. size)
50
47
}
51
48
. onReceive ( self . timer) { _ in
52
- if self . currentValue < self . model. maxValue {
49
+ if self . model . currentValue < self . model. maxValue {
53
50
let step = ( self . model. maxValue - self . model. minValue) / 100
54
- self . currentValue = min (
51
+ self . model . currentValue = min (
55
52
self . model. maxValue,
56
- self . currentValue + CGFloat( Int . random ( in: 1 ... 20 ) ) * step
53
+ self . model . currentValue + CGFloat( Int . random ( in: 1 ... 20 ) ) * step
57
54
)
58
55
} else {
59
- self . currentValue = self . model. minValue
56
+ self . model . currentValue = self . model. minValue
60
57
}
61
- self . model. label = " \( Int ( self . currentValue) ) % "
58
+ self . model. label = " \( Int ( self . model . currentValue) ) % "
62
59
}
63
60
}
64
61
}
65
62
66
63
// MARK: - Helpers
67
64
68
- private static var initialValue : Double {
69
- return 0.0
70
- }
71
-
72
65
private static var initialModel = CircularProgressVM {
73
66
$0. label = " 0% "
74
- $0. style = . light
67
+ $0. currentValue = 0.0
75
68
}
76
69
}
77
70
0 commit comments