79451726

Date: 2025-02-19 14:36:54
Score: 1
Natty:
Report link

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:)

Reasons:
  • Probably link only (1):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Ilya Biltuev