@@ -2,10 +2,18 @@ import SwiftUI
2
2
import SpeedManagerModule
3
3
import SpeedometerSwiftUI
4
4
5
+ extension Double {
6
+ /// Returns the double value fixed to one decimal place.
7
+ func fixedToOneDecimal( ) -> String {
8
+ return String ( format: " %.1f " , self )
9
+ }
10
+ }
11
+
5
12
struct ContentView : View {
6
13
@StateObject var speedManager = SpeedManager ( speedUnit: . kilometersPerHour)
7
14
@State var progress : CGFloat = 0.0
8
- let maxSpeed : CGFloat = 200.0
15
+ @State private var speed : TimeInterval = 0.01
16
+ let maxSpeed : CGFloat = 200.0 // Define a constant maximum speed
9
17
10
18
var body : some View {
11
19
VStack {
@@ -16,18 +24,17 @@ struct ContentView: View {
16
24
Text ( " \( speedManager. speed. fixedToOneDecimal ( ) ) km/h " )
17
25
. monospaced ( )
18
26
19
- GaugeView (
20
- animationDuration: 0.1 ,
21
- progress: progress,
22
- numberOfSegments: 200 ,
23
- step: 20
24
- )
25
- . frame ( width: 300 , height: 300 )
26
- . onAppear {
27
- updateProgress ( )
28
- }
29
- . onChange ( of: speedManager. speed) { newSpeed in
30
- updateProgress ( )
27
+ TimelineView ( . animation( minimumInterval: speed) ) { context in
28
+ GaugeView (
29
+ animationDuration: speed,
30
+ progress: progress,
31
+ numberOfSegments: 200 ,
32
+ step: 20
33
+ )
34
+ . onChange ( of: context. date) { oldValue, newValue in
35
+ updateProgress ( )
36
+ }
37
+ . frame ( width: 300 , height: 300 )
31
38
}
32
39
33
40
default :
@@ -41,6 +48,7 @@ struct ContentView: View {
41
48
withAnimation ( . easeInOut( duration: 0.5 ) ) {
42
49
progress = CGFloat ( speedManager. speed / maxSpeed)
43
50
}
51
+ speed = 0.01 // Adjust speed interval as needed
44
52
}
45
53
}
46
54
@@ -49,10 +57,3 @@ struct ContentView_Previews: PreviewProvider {
49
57
ContentView ( )
50
58
}
51
59
}
52
-
53
- extension Double {
54
- /// Returns the double value fixed to one decimal place.
55
- func fixedToOneDecimal( ) -> String {
56
- return String ( format: " %.1f " , self )
57
- }
58
- }
0 commit comments