SwiftUIPager icon indicating copy to clipboard operation
SwiftUIPager copied to clipboard

[FEAT] Provide option to pass-down the swipe gesture, if user tries to swipe beyond end element

Open chris-hatton opened this issue 5 years ago • 2 comments

Hi @fermoya ,

Thank you for SwiftUIPager. I have a use case for nested pagers that might already be supported in a way I cannot see; or could be better supported in future.

To explain; here's an in-development screenshot of my open-source iOS App 'Hydrant Art', to accompany the existing Android version.

Screen Shot 2020-11-05 at 10 40 22 pm

The screen shown is the Hydrant 'detail' view, in which I want to swipe left/right through the Hydrants and their photos. If there is a single photo for each Hydrant, this would be a simple case of one pager. But because their may be multiple photos per Hydrant I am nesting Pagers within each other: The inner pager surrounding only the photo(s), and an outer pager for the whole screen content.

What I would like to happen, is that when swiping on the nested photo area, if the first or last element is reached and the user tries to swipe beyond the first/last photo, then the swipe gesture instead acts upon the outer Pager, to swipe the overall Hydrant page instead. In this way, the user could swipe through all photos and all hydrants by continuously swiping on the photo area in one direction.

I could imagine a setting like swipePastExtentBehavior with options to:

  • bounce (current default)
  • passthrough (pass through swipe gesture when in the 'end' direction) <- This is the option I'm requesting
  • block (swallow the gesture/don't bounce - just another possibly desired behaviour)

chris-hatton avatar Nov 05 '20 12:11 chris-hatton

Hi @chris-hatton , thanks for your feedback and your suggestion. I know what you mean and understand the feature. I've honestly had a lot of trouble with Gesture in SwiftUI. You see, in UIKit you can create your own gestures and update the state:

  • recognized
  • start
  • changed
  • failed
  • cancelled
  • ended

You'd normally "recognize" it and based on certain conditions you'd make it fail. The problem in with SwiftUI.Gesture is that there's no way to do the same.

I'm gonna give it a thought or two, though. It's been a while I don't take a look at this, maybe I can come up with a workaround this time. I'll keep you posted, thanks 😃

fermoya avatar Nov 05 '20 12:11 fermoya

@chris-hatton , I've come up with a workaround for this. It's not elegant and I wish I could propagate the touch and make the child Pager fail, but for now it works and can be implemented.

Take a look at version 1.14.0-beta.4. I've implemented new modifiers:

  • bounces
  • onDraggingChanged
  • onDraggingEnded

You can take a look at NestedExampleView, I've implemented the changes there if you wanna take a look.

fermoya avatar Nov 26 '20 15:11 fermoya