Skip to content

Commit

Permalink
tmp illustration for #61
Browse files Browse the repository at this point in the history
  • Loading branch information
dmrschmidt committed Mar 3, 2023
1 parent a133d46 commit 578a526
Showing 1 changed file with 26 additions and 4 deletions.
Expand Up @@ -54,6 +54,9 @@ struct SwiftUIExampleView: View {
.padding(.vertical, 20)
}

@State var progress: Double = 0
let timer = Timer.publish(every: 0.2, on: .main, in: .common).autoconnect()

@available(iOS 15.0, *)
@ViewBuilder
private var recordingExample: some View {
Expand Down Expand Up @@ -85,11 +88,30 @@ struct SwiftUIExampleView: View {
.padding()

if let audioURL {
WaveformView(
audioURL: audioURL,
configuration: configuration,
renderer: CircularWaveformRenderer(kind: .ring(0.7))
let configuration: Waveform.Configuration = .init(
style: .striped(.init(color: .gray, width: 1, spacing: 2))
)

GeometryReader { proxy in
ZStack(alignment: .leading) {
// Static waveform view, showing the whole file
WaveformView(audioURL: audioURL, configuration: configuration)
.frame(width: proxy.size.width)

// Animated progress indicator, masked to the same waveformView, to show the progress
let width = min(progress * proxy.size.width, proxy.size.width)
Rectangle()
.frame(width: width)
.foregroundColor(.blue)
.mask(alignment: .leading) {
WaveformView(audioURL: audioURL, configuration: configuration)
.frame(width: proxy.size.width)
}
.animation(.linear, value: progress)
}
}.onReceive(timer) { _ in
self.progress = (self.progress + 0.02).truncatingRemainder(dividingBy: 1)
}
}

VStack {
Expand Down

0 comments on commit 578a526

Please sign in to comment.