For iOS 18
You can easily detect scroll direction by using onScrollGeometryChange
ScrollView(.vertical) {
...
}
.onScrollGeometryChange(for: CGFloat.self, of: { geometry in
geometry.contentOffset.y
}, action: { oldValue, newValue in
if newValue > oldValue {
print("SCROLL DOWN")
} else {
print("SCROLL UP")
}
})
Apple doc: https://developer.apple.com/documentation/swiftui/view/onscrollgeometrychange(for:of:action:)