If you use a ProgressView
inside a List
, it will probably disappear when you scroll away and then back. Using .id(UUID())
did not work for me, but @desudesudesu's answer was the only one that did.
I created a custom view for this, and when you use that inside a List
the problem goes away:
// Fixes SwiftUI ProgressView bug in List: reset id on disappear to avoid frozen/hidden spinner
struct ListProgressView: View {
@State
private var progressViewID = UUID()
var body: some View {
ProgressView()
.id(self.progressViewID)
.onDisappear {
self.progressViewID = UUID()
}
}
}
#Preview {
List {
ListProgressView()
ForEach(0..<100, id: \.self) {
Text("Item \($0)")
}
}
}