1

I have the following view:

List { 
  VStack {
    InnerVStack { 
      ...
    }

    InnerVStack { 
      ...
      
      Cell()
       .background { 
         NavigationLink()
      }

      ...
    }
  }
}

The problem is, that whenever the whole VStack is tapped, the NavigationLink is activated.

I have seen some more people deal with the same problem, but really to no avail:

NavigationLink inside List applies to HStack instead of each element

Lists that have a VStack containing a NavigationLink makes the whole area of the VStack tappable instead of only the SubView

I want to achieve such behavior, that only when Cell is tapped, then the NavigationLink is activated and user is redirected to another scene.

Ctibor Šebák
  • 133
  • 1
  • 14
  • Why do you put link in background of cell ? – Ptit Xav Jun 21 '22 at 11:56
  • Because I am getting rid of the system arrow that comes with NavigationLink by providing custom `Cell` and setting the `NavigationLink`'s opacity to zero. If I put the `NavigationLink` directly into the `InnerVStack` (without embedding it to background of `Cell`), the behavior is identical. – Ctibor Šebák Jun 21 '22 at 11:59
  • I think the main problem is that in SwiftUI the view usually take all the space it can use. Try to set some background colour or border line to find which are the limit of the different views you are displaying. – Ptit Xav Jun 21 '22 at 12:17
  • That is correct, I know that the issue is that the background of the `Cell` is taking up the whole `VStack`, however I am trying to fix it in a clean way, so far I have wrapped the `Cell` in a `Button` while setting the `Cell` as the button's label. Afterwards disabling tap gesture on the whole `List` with `.onTapGesutre { return }`. This works, but seems more like a hack than intended way of achieving desired behavior. – Ctibor Šebák Jun 21 '22 at 12:58

0 Answers0