Skip to content

Commit 8d4f5e7

Browse files
committed
Unified Track list rendering, fixed playback indicator bugs
1 parent dd66ac0 commit 8d4f5e7

11 files changed

Lines changed: 634 additions & 1107 deletions
Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,43 @@
11
import SwiftUI
22

33
struct PlayingIndicator: View {
4-
@State private var isAnimating = false
4+
@State private var animationPhases: [CGFloat] = [0, 0, 0]
5+
// Update 60 times per second for smooth animation
6+
private let timer = Timer.publish(every: 1.0/60.0, on: .main, in: .common).autoconnect()
57

68
var body: some View {
79
HStack(spacing: 2) {
810
ForEach(0..<3) { index in
911
RoundedRectangle(cornerRadius: 1)
1012
.fill(Color.accentColor)
11-
.frame(width: 3, height: isAnimating ? 12 : 4)
12-
.animation(
13-
Animation.easeInOut(duration: 0.4)
14-
.repeatForever(autoreverses: true)
15-
.delay(Double(index) * 0.1),
16-
value: isAnimating
17-
)
13+
.frame(width: 3, height: barHeight(for: index))
14+
.animation(.none) // Disable implicit animations for smoother manual control
1815
}
1916
}
2017
.frame(width: 16, height: 12)
2118
.clipped()
22-
.onAppear {
23-
isAnimating = true
24-
}
25-
.onDisappear {
26-
isAnimating = false
19+
.onReceive(timer) { _ in
20+
updateAnimation()
2721
}
2822
}
23+
24+
private func barHeight(for index: Int) -> CGFloat {
25+
let phase = animationPhases[index]
26+
// Smoother sine wave calculation
27+
let height = 6 + (6 * sin(phase))
28+
return max(2, height) // Ensure minimum height of 2
29+
}
30+
31+
private func updateAnimation() {
32+
// Slower, smoother animation with different speeds for each bar
33+
animationPhases[0] += 0.08
34+
animationPhases[1] += 0.10
35+
animationPhases[2] += 0.12
36+
}
37+
}
38+
39+
#Preview {
40+
PlayingIndicator()
41+
.padding()
42+
.background(Color.gray.opacity(0.1))
2943
}

0 commit comments

Comments
 (0)