I have following code and trying to simulate a heavy task. Where do I have to activate and deactivate the progressView? In this Video it doesn't look right (the cirle should as long rotate as the number is about to change, when it’s changing the circle should disappear): Video_imgur
struct ContentViewDispatch: View{
@State var button_tap_count = 0
@State var dispatch_start = 0
@State var i = 0
@State var showProgress = false
var body: some View{
VStack{
Text("Tapped: \(button_tap_count)")
Text("Dispatch: \(dispatch_start)")
Text("number: \(i)")
Button("reset"){
i = 0
}
ProgressView().progressViewStyle(CircularProgressViewStyle()).opacity(showProgress ? 1 : 0)
Button("count"){
button_tap_count += 1
var k = i
DispatchQueue.global(qos: .userInitiated).async {
DispatchQueue.main.async {
showProgress = true <----- activate
dispatch_start += 1
}
for _ in 0..<5_000_000{
k += 1
}
DispatchQueue.main.async {
showProgress = false <------ deactivate
i = k
}
}
}
}
}
}