@@ -13,7 +13,7 @@ struct WeeklyWorkoutTrackerView: View {
13
13
// MARK: - Properties
14
14
15
15
@ObservedObject var viewModel : ProfileView . ViewModel
16
- @State private var animationProgress : Double = 0
16
+ @State private var animationProgress : [ Double ] = Array ( repeating : 0 , count : 7 )
17
17
18
18
// Weekday abbreviations
19
19
private let weekdays = [ " Mon " , " Tue " , " Wed " , " Thu " , " Fri " , " Sat " , " Sun " ]
@@ -22,8 +22,8 @@ struct WeeklyWorkoutTrackerView: View {
22
22
@State private var workoutDays : [ Bool ] = [ false , false , false , false , false , false , false ]
23
23
24
24
// Animation timing
25
- private let animationDuration : Double = 0.05
26
- private let delayBetweenDays : Double = 0.2
25
+ private let animationDuration : Double = 0.5
26
+ private let delayBetweenDays : Double = 0.3
27
27
28
28
// Circle dimensions
29
29
private let circleSize : CGFloat = 24
@@ -80,14 +80,16 @@ struct WeeklyWorkoutTrackerView: View {
80
80
Circle ( )
81
81
. fill ( Constants . Colors. yellow)
82
82
. frame ( width: circleSize, height: circleSize)
83
- . opacity ( animationProgress > Double ( index) ? 1 : 0 )
83
+ . scaleEffect ( animationProgress [ index] )
84
+ . opacity ( animationProgress [ index] )
84
85
}
85
86
86
87
if workoutDays [ index] {
87
88
Image ( systemName: " checkmark " )
88
89
. font ( . system( size: 14 , weight: . bold) )
89
90
. foregroundColor ( . black)
90
- . opacity ( animationProgress > Double ( index) ? 1 : 0 )
91
+ . scaleEffect ( animationProgress [ index] )
92
+ . opacity ( animationProgress [ index] )
91
93
}
92
94
}
93
95
}
@@ -132,23 +134,21 @@ struct WeeklyWorkoutTrackerView: View {
132
134
let day = 25 + index
133
135
workoutDays [ index] = workoutDaysSet. contains ( day)
134
136
}
137
+
138
+ // Reset animation progress
139
+ animationProgress = Array ( repeating: 0 , count: 7 )
135
140
}
136
141
137
- /// Animates the workout day indicators sequentially from left to right.
142
+ /// Animates the workout day indicators sequentially from left to right with fade-in effect
138
143
private func animateWorkouts( ) async {
139
- animationProgress = 0
140
-
141
- for index in weekdays. indices {
142
- do {
143
- try await Task . sleep ( for: . seconds( 0.25 ) )
144
+ for index in weekdays. indices where workoutDays [ index] {
145
+ // Add delay between animations
146
+ try ? await Task . sleep ( for: . seconds( delayBetweenDays) )
144
147
145
- await MainActor . run {
146
- withAnimation ( . easeInOut( duration: animationDuration) ) {
147
- animationProgress = Double ( index + 1 )
148
- }
148
+ await MainActor . run {
149
+ withAnimation ( . easeIn( duration: animationDuration) ) {
150
+ animationProgress [ index] = 1.0
149
151
}
150
- } catch {
151
- print ( " Error during animation delay: \( error) " )
152
152
}
153
153
}
154
154
}
0 commit comments