5

I'm trying to implement a UICollectionView like View in SwiftUI which basically works fine. But when I scroll/drag inside the scroll view to scroll down, the tap is recognized on the NavigationLink and then navigating to the detail view, even if I just wanted to scroll down.

Any ideas what might be causing this? Additional info: The whole NavigationView is opened from a .sheet from another view (as you might notice in the screenshot). I tried adding a "manual" link by setting the tag property on the link and setting the tag within a TapGesture, but this doesn't work either.

Here is a short example where the error can be reproduced. Scrolling down will activate a tap on one of the white rectangles.

View before drag gesture on scroll view

View during drag gesture, tap is already recognized on NavigationLink

Navigation view pushes to detail view after drag gesture

    var body: some View {
        NavigationView {
            ScrollView {
                VStack {
                    ForEach(0..<6) { i in
                        NavigationLink(destination: Text("Detail")) {
                            Rectangle()
                                .background(Color.red)
                                .frame(width: 365, height: 100, alignment: .center)
                        }
                    }
                }
            }
            .navigationViewStyle(StackNavigationViewStyle())
            .navigationBarTitle("Items")
        }
    }
Melvil
  • 51
  • 3
  • 1
    Your code works as expected as a stand-alone view, just not presented in a sheet. This most likely means that Apple didn't expect a `NavigationView` to be used within `.sheet()`, and didn't test for weird effects like this. I'd file feedback (http://feedbackassistant.apple.com). – John M. Oct 17 '19 at 21:39
  • 1
    Definitely looks like a major oversight on Apples side. I've been trying to cancel the navigation link when a drag starts by doing `.highPriorityGesture(DragGesture())` on the NavigationLink and this works but it also hijacks the scrollviews drag :/ – Casper Zandbergen Oct 18 '19 at 15:53
  • Thanks everybody, I filed a feedback at Apple – Melvil Oct 18 '19 at 20:28
  • 2
    I think the issue is that the SwiftUI ScrollView doesn't delay it's content touches the way UIKit does: https://developer.apple.com/documentation/uikit/uiscrollview/1619398-delayscontenttouches – Casper Zandbergen Oct 22 '19 at 12:49

0 Answers0