1

I have the following NavigationLink:

NavigationLink(destination:
         TrendSlider(
            title: .constant(title),
             col: .constant(self.dataModel.queryColumnSeasonWinPercentageTeam1),
             opIndx: self.$dataModel.seasonWinPercentageTeam1OperatorIndxValue,
             val: self.$dataModel.seasonWinPercentageTeam1SliderValue,
             lBound: .constant(self.dataModel.seasonWinPercentageTeam1Values.first!) ,
             uBound: .constant(self.dataModel.seasonWinPercentageTeam1Values.last!),
             lRange: self.$dataModel.seasonWinPercentageTeam1RangeSliderLowerValue ,
             uRange: self.$dataModel.seasonWinPercentageTeam1RangeSliderUpperValue,
             step: .constant(1.0),
             displayReadableQuery: $readableQuery

   )) {
       HStack {
          if readableQuery.hasSuffix("IS ANY") {
                Text(title)
                Spacer()
                Text("IS ANY").foregroundColor(Color("TPLightGrey"))
            }else{
                Text(readableQuery).foregroundColor(Color("TPOrange"))

            }
       }
   }.simultaneousGesture(TapGesture().onEnded{
       sendViewSelectionEvent(name: self.title, referral: "Game")

   })

If I leave in the ".simultaneousGesture...", then the tap on the Text elements don't trigger the NavigationLink action, however the rest of the row does work.

If I remove .simultaneousGesture, the row can be tapped anywhere again.

Bug?

jimijon
  • 2,046
  • 1
  • 20
  • 39

2 Answers2

5

Adding the .simultaneousGesture(:) call is creating a tap gesture recognizer on the label of the NavigationLink, not on the row itself. Two facts about gesture recognizers explain the observed behavior.

  1. The label of the NavigationLink is actually sitting above the list/form row (see picture), meaning it will now intercept any taps before they reach the list/form row.
  2. Any part of a view with opacity of 0 will not intercept taps, allowing it to pass through to the next gesture recognizer; in this case, the list/form row.

So when you tap on one of the text views, the tap is handled by the TapGesure.onEnded() closure. But when you tap on the space in between, the tap "passes through" and gets handled by the recognizer on the list/form row, triggering the NavigationView seque.

So, a SwiftUI design decision, and not a bug. Currently, List/Form is not built to recognize custom gestures while maintaining navigation functionality. If you have a use case for this kind of behavior, submit some feedback, and maybe we'll see it next year.

View Hierarchy

John M.
  • 8,892
  • 4
  • 31
  • 42
0

Thank you for the explanation. It makes sense. And it made me look for a proper way to trigger my call.

.onAppear(){ .... }

I was trying to emulate a viewWillAppear type event on tap of the navlink. I put the onAppear on the vStack and it works great.

jimijon
  • 2,046
  • 1
  • 20
  • 39