0

I am making a list of questions sets and want the whole row to navigate to next view (every row has a different destination view), but only the area next to the text is tappable. I tried creating a SetRow() outside of List and it was working completely fine, but when its inside of List only the empty area is working.

Red is the working area

List code here:

NavigationView {
            VStack {
                SearchBar(input: $searchInput)
                List(viewModel.filterList(by: searchInput)) { setVM in
                    NavigationLink(destination:
                        SetView(viewModel: QuestionListViewModel(
                                            emoji: setVM.questionSet.emoji,
                                            title: setVM.questionSet.title,
                                            setID: setVM.questionSet.id)
                            ))
                    {
                        SetRow(viewModel: setVM)
                    }
                    .onLongPressGesture(minimumDuration: 1) {
                        selectedSetVM = setVM
                        showDeleteAlert.toggle()
                    }
                    
                }
                .listStyle(PlainListStyle())
                
            }

and SetRow code here:

HStack {
            Text(viewModel.questionSet.emoji)
                .font(.system(size: 50))
            VStack(alignment: .leading) {
                Text(viewModel.questionSet.title)
                    .font(.system(size: 20, weight: .semibold, design: .default))
                VStack(alignment: .leading) {
                    Text("Questions: \(viewModel.questionSet.size)")
                        .font(.system(size: 15, weight: .light, design: .default))
                        .foregroundColor(.gray)
                    Text("Updated: \(viewModel.questionSet.lastUpdated, formatter: taskDateFormat)")
                        .font(.system(size: 15, weight: .light, design: .default))
                        .foregroundColor(.gray)
                }
            }
            Spacer()
        }
        .padding(.top, 10)
Maguss
  • 3
  • 1

1 Answers1

1

The problem comes with your 'longPressGesture' which wants to control the content of your row and listen for longPresses. To avoid this you can use 'onTapGesture' to control the activation of the NavigationLink and 'onLongPressGesture' to activate your actionSheet or Alert.

Here is a short code example that demonstrates the usage: https://stackoverflow.com/a/67099257

Alex B
  • 131
  • 7
  • Thanks, you were right! It doesn´t even occured to me that longPressGesture could have an effect on it. – Maguss Jul 10 '21 at 19:03