diff --git a/bitchat/Views/RealtimeScrollingWaveform.swift b/bitchat/Views/RealtimeScrollingWaveform.swift new file mode 100644 index 00000000..7a0caf4d --- /dev/null +++ b/bitchat/Views/RealtimeScrollingWaveform.swift @@ -0,0 +1,60 @@ +import SwiftUI +import Combine + +/// Real-time scrolling waveform for live recording. +/// Provide a normalized amplitude [0,1]. The view maintains a sliding window of bars. +struct RealtimeScrollingWaveform: View { + var amplitudeNorm: CGFloat + var bars: Int = 240 + var barColor: Color = Color(red: 0, green: 1, blue: 0.5) // neon-ish green + + @State private var samples: [CGFloat] = [] + @State private var ticker = Timer.publish(every: 0.02, on: .main, in: .common).autoconnect() + + var body: some View { + GeometryReader { geo in + Canvas { ctx, size in + let w = size.width + let h = size.height + guard w > 0 && h > 0 else { return } + let n = samples.count + guard n > 0 else { return } + let stepX = w / CGFloat(n) + let midY = h / 2 + let stroke: CGFloat = 1.2 + + for i in 0.. 0 { samples.removeFirst(overflow) } + } + } + } +}