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!
Asked
Active
Viewed 7,209 times
14
-
1Add a drag gesture. – E.Coms Jan 07 '20 at 00:22
1 Answers
33
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.

Martijn Pieters
- 1,048,767
- 296
- 4,058
- 3,343

Asperi
- 228,894
- 20
- 464
- 690
-
2
-
2
-
1The `onChanged` closure is called only once. What is the reason for this? – PGDev Jul 29 '21 at 12:08
-
2