It appears that using the listStyle modifier makes the phase modifier work:
List {
ForEach(0..<100, id: \.self) { i in
Text("Hello, World! \(i)")
.id(i)
.onAppear { visible[i] = true }
.onDisappear { visible[i] = false }
}
}
// without modifier // ❌
// .listStyle(.automatic) // ❌
// .listStyle(.grouped) // ✅
// .listStyle(.inset) // ✅
// .listStyle(.insetGrouped) // ✅
// .listStyle(.plain) // ✅
// .listStyle(.sidebar) // ✅
.onScrollPhaseChange { old, new, _ in
print("old: \(old), new: \(new)")
if old != .idle, new == .idle {
let message = visible.keys.sorted().reduce(into: "") { base, element in
base += "i: \(element) (\(visible[element]?.description ?? "null")), "
}
print(message)
}
}
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: