Unleash the power of UIScrollView
when just using SwiftUI ScrollView
.
A dummy "spy" view you can add inside your ScrollView
that will attach a UILongPressGestureRecognizer
to it and gives you a binding to the point where the finger is in the direct superview of the spy.
SwiftUI ScrollView
is getting better every release, but currently (iOS 14) you can't add extra gesture recognizers. This is often needed for more complex interactions, this little spy gets that job done.
Works great cases I encountered so far, no issues with state or reimplementing ScrollView yourself. You only need something like a ZStack
to make the spy not take op screen realestate.
Just give it a try! :)
- To be less dependent on Apples SwiftUI
ScrollView
implementation; Fully wrapUIScrollView
in aUIViewControllerRepresentable
. (Note: You do a lot of work Apple already did.) - For a nicer API; Make a wrapper that you can apply like a view modifier like this. (Note: This has issues with passing down state.)
Yes, I've put this in the public domain!