Given a List in SwiftUI, once panning begins, updating of views in the list seems to pause until the scrolling has been stopped. Is there a way to prevent this?
Consider the following code:
class Model: ObservableObject, Identifiable {
@Published var offset: CGFloat = 0
let id = UUID()
private var timer: Timer!
init() {
timer = Timer.scheduledTimer(withTimeInterval: 0.5, repeats: true, block: { _ in
self.update()
})
}
func update() {
offset = CGFloat.random(in: 0...300)
}
}
struct ContentView: View {
@ObservedObject var model1 = Model()
@ObservedObject var model2 = Model()
@ObservedObject var model3 = Model()
@ObservedObject var model4 = Model()
var body: some View {
List {
ForEach([model1, model2, model3, model4]) {
Rectangle()
.foregroundColor(.red)
.frame(width: $0.offset, height: 30, alignment: .center)
.animation(.default)
}
}
}
}
Will result in this behaviour: