I am working on a custom delay Animation which I started my version 0.0.0 with asyncAfter and then updated my code to Version 1.0.0 using sleep, I would like to know if there is a native and easy way for such a delay Animation instead my custom way, see the deference in gif or code.
PS: If you see any bad coding or upgradable code, please let me know.
struct ContentView: View {
@State private var array: [Int] = [Int]()
var body: some View {
VStack(spacing: 10.0) {
Button("remove all") { array.removeAll() }.foregroundColor(.red)
Button("Way 1") { array += Array(repeating: 0, count: 5) }
Button("Way 2(Custom Code)") {
DispatchQueue.global(qos: .background).async {
for index in 0...5 {
usleep(50_000)
DispatchQueue.main.async { array.append(index) }
}
}
}
ForEach(array.indices, id:\.self) { index in
Image(systemName: "arrowtriangle.up.fill").scaledToFit().frame(width: 25, height: 25)
}
}
.animation(.default, value: array)
}
}
