SwiftUIPager: Pager's scroll blocks the ScrollView's scroll

I’ve seen there was a similar issue (#3) but then it was closed and an entirely different use case with ScrollView was discussed, so I am going to post this.

Basically, if a Pager view is placed inside a ScrollView with vertical scroll, the former blocks the parent’s scroll, unless the drag gesture starts outside the Pager’s view area.

This is not an issue caused by Pager itself, but there might be solutions that would work if applied to the library. I haven’t seen any perfect solutions yet though.

There are some discussions here: https://stackoverflow.com/questions/57700396/adding-a-drag-gesture-in-swiftui-to-a-view-inside-a-scrollview-blocks-the-scroll. The trick with the button (https://stackoverflow.com/a/59961959/1719285) can be applied outside the library, but this then blocks the tap gestures inside each view (in my case, the remove button). The only solution that worked more or less OK (ish) was to have DragGesture(minimumDistance: 30, coordinateSpace: .local) for the swipeGesture of the library.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 16 (10 by maintainers)

Commits related to this issue

Most upvoted comments

Version 1.5.0 released. Using suggested hack till SwiftUI offers new options. Pager works fine inside a ScrollView now.

In case Pager is needed in a interactive modal, please use highPriorityGesture.

Hi @codetheweb,

Thanks for your comment. There’s an sample App in the repository which has a tab called “Presented”: Screenshot 2020-05-22 at 08 33 57 This is an edge situation. Now, your code is skipping scrolling the pages if the dragging isn’t in the horizontal axis. But the gesture is already recognized! This means it won’t let the ScrollView scroll or the presented view to be dismissed.

In UIKit, if you create a custom gesture which should only be triggered when scrolling horizontally, you make it fail when scrolling vertically. This way the gesture isn’t recognized and some other View can try to recognize it. This isn’t the case with SwiftUI, there’s not such thing.

The best workaround is suggested above, but again it introduces an issue with the “Presented” tab in the Sample project