The TextField in the following code makes the List very lag when scrolling. Note that I'm not even changing the property used by TextField. I'm able to solve this by changing my model to a ObservableObject but I would like to keep as a struct if possible. Does anyone have any solution? Thanks!
struct Model: Identifiable {
let id = UUID()
var text: String = "Lorem Ipsum"
var bool = false
}
struct RowView: View {
@Binding var model: Model
var body: some View {
TextField("", text: $model.text)
.task {
try? await Task.sleep(for: .seconds(0.5))
model.bool.toggle()
}
}
}
struct ContentView: View {
@State var models = (1...100).map({ _ in Model() })
var body: some View {
List {
ForEach($models) { $model in
RowView(model: $model)
}
}
}
}