Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI: how to detect when List is scrolled? [closed]

I have a view with a search bar at the top and a SwiftUI List below. I need to detect when the List is scrolled so I can dismiss the search bar keyboard. How would I call some code when the List is scrolled? Thanks!

like image 397
pejalo Avatar asked Jan 06 '20 23:01

pejalo


1 Answers

I recommend to use simultaneousGesture modifier as in below:

List {
  // ... your list items
}
.simultaneousGesture(DragGesture().onChanged({ _ in
    // if keyboard is opened then hide it
}))

Update: verified with Xcode 13.3 / iOS 15.4 - for the use-case formulated by PO still works fine.

like image 121
Asperi Avatar answered Nov 05 '22 19:11

Asperi