1

I would like to have multiple NavigationLink inside the same List row to replicate a CollectionView behaviour.

Here is my code :

var body: some View {
        NavigationView {
            ZStack {
                Color(.black)
                    .edgesIgnoringSafeArea(.all)
                VStack(alignment: .center, spacing: 10) {
                    SearchBar(text: $searchViewModel.searchText)
                    List {
                        ForEach(0..<searchViewModel.items.count, id: \.self) { index in
                            HStack(alignment: .center, spacing: 10) {
                                ForEach(self.searchViewModel.items[index], id: \.id) { item in
                                    self.cellFor(item)
                                }
                                Spacer()
                            }
                        }
                    }
                }
            }
            .navigationBarTitle("")
            .navigationBarHidden(true)
        }
    }

func movieCellFor(_ item: SearchItemViewModel) -> some View {
        return NavigationLink(destination: MovieDetails(movieId: item.sourceId)) {
            cellUiFor(item)
        }
    }

If I tap one of my cells, it just seems to "consume" every NavigationLink in the row. I think this is because of the default List behaviour. Is there a way to prevent it and to put multiple NavigationLink in a row ? I know that i could put my content into a ScrollView and a VStack but i'd like to keep the reuse system of the List component.

EDIT:

    func movieCellFor(_ item: SearchItemViewModel) -> some View {
         return Button(action: {}) {
            NavigationLink(destination: MovieDetails(movieId: item.sourceId)) { cellUiFor(item) }
         }
Q. Eude
  • 841
  • 11
  • 24
  • It is already solved [here](https://stackoverflow.com/a/61188788/12299030), while topic is named differently. – Asperi May 18 '20 at 12:26
  • I don't really understand the answer on this post since when I try to apply the same thing to my case it's not working, this idea is just to add a kind of ButtonStyle to the whole row ? – Q. Eude May 18 '20 at 15:42
  • No, to every link - every link should be hidden in own button with custom style, otherwise List detect it and apply to entire row. – Asperi May 18 '20 at 15:46
  • Wrapping my cell into a `Button` results in `NavigationLink` isn't called – Q. Eude May 18 '20 at 15:56
  • I just changed my code as in my edit on first post, but `NavigationLink` doesn't seems to be triggered – Q. Eude May 18 '20 at 16:12

0 Answers0