Skip to content

Commit ce2835f

Browse files
committed
update Demo
1 parent 6e3cf6c commit ce2835f

File tree

2 files changed

+23
-22
lines changed

2 files changed

+23
-22
lines changed

Demo/Demo/Demo.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@
314314
"INFOPLIST_KEY_UIStatusBarStyle[sdk=iphonesimulator*]" = UIStatusBarStyleDefault;
315315
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
316316
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
317-
IPHONEOS_DEPLOYMENT_TARGET = 16.1;
317+
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
318318
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
319319
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
320320
MACOSX_DEPLOYMENT_TARGET = 12.4;
@@ -358,7 +358,7 @@
358358
"INFOPLIST_KEY_UIStatusBarStyle[sdk=iphonesimulator*]" = UIStatusBarStyleDefault;
359359
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
360360
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
361-
IPHONEOS_DEPLOYMENT_TARGET = 16.1;
361+
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
362362
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
363363
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
364364
MACOSX_DEPLOYMENT_TARGET = 12.4;

Demo/Demo/Demo/ContentView.swift

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,18 @@ import SwiftUI
22
import SpeedManagerModule
33
import SpeedometerSwiftUI
44

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+
512
struct ContentView: View {
613
@StateObject var speedManager = SpeedManager(speedUnit: .kilometersPerHour)
714
@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
917

1018
var body: some View {
1119
VStack {
@@ -16,18 +24,17 @@ struct ContentView: View {
1624
Text("\(speedManager.speed.fixedToOneDecimal()) km/h")
1725
.monospaced()
1826

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)
3138
}
3239

3340
default:
@@ -41,6 +48,7 @@ struct ContentView: View {
4148
withAnimation(.easeInOut(duration: 0.5)) {
4249
progress = CGFloat(speedManager.speed / maxSpeed)
4350
}
51+
speed = 0.01 // Adjust speed interval as needed
4452
}
4553
}
4654

@@ -49,10 +57,3 @@ struct ContentView_Previews: PreviewProvider {
4957
ContentView()
5058
}
5159
}
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

Comments
 (0)