From d35d6099006d128ec78a41cd21886ea2c085d967 Mon Sep 17 00:00:00 2001 From: mahal raskin Date: Wed, 12 Jun 2024 22:19:41 +0200 Subject: [PATCH] Refresh waveform when a new URL is set, Issue #89 --- .../Visualizations/AudioFileWaveform.swift | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Sources/AudioKitUI/Visualizations/AudioFileWaveform.swift b/Sources/AudioKitUI/Visualizations/AudioFileWaveform.swift index 971afa0..28938de 100644 --- a/Sources/AudioKitUI/Visualizations/AudioFileWaveform.swift +++ b/Sources/AudioKitUI/Visualizations/AudioFileWaveform.swift @@ -35,7 +35,7 @@ public struct AudioFileWaveform: View { } public var body: some View { - Group { + let group = Group { if viewModel.rmsValues.count > 2 { AudioWaveform(rmsVals: viewModel.rmsValues) .fill(color) @@ -43,8 +43,18 @@ public struct AudioFileWaveform: View { AudioWaveform(rmsVals: viewModel.rmsValues) .stroke(color) } - }.onAppear { - viewModel.update(url: url, rmsSamplesPerWindow: rmsSamplesPerWindow) + } + if #available(iOS 17.0, *) { + group.onChange(of:url) { + viewModel.update(url: url, rmsSamplesPerWindow: rmsSamplesPerWindow) + } + .onAppear { + viewModel.update(url: url, rmsSamplesPerWindow: rmsSamplesPerWindow) + } + } else { + group.onAppear { + viewModel.update(url: url, rmsSamplesPerWindow: rmsSamplesPerWindow) + } } } }