Allow custom tap gesture in List but maintain default selection gesture

I'm trying to create a List that allows multiple selection. Each row can be edited but the issue is that since there's a tap gesture on the Text element, the list is unable to select the item.

Here's some code:

import SwiftUI

struct Person: Identifiable {
    let id: UUID
    let name: String
    
    init(_ name: String) {
        self.id = UUID()
        self.name = name
    }
}

struct ContentView: View {
    @State private var persons = [Person("Peter"), Person("Jack"), Person("Sophia"), Person("Helen")]
    @State private var selectedPersons = Set<Person.ID>()
    
    var body: some View {
        VStack {
            List(selection: $selectedPersons) {
                ForEach(persons) { person in
                    PersonView(person: person, selection: $selectedPersons) { newValue in
                        // ...
                    }
                }
            }
        }
        .padding()
    }
}

struct PersonView: View {
    var person: Person
    
    @Binding var selection: Set<Person.ID>
    
    var onCommit: (String) -> Void = { newValue in }
    
    @State private var isEditing = false
    @State private var newValue = ""
    
    @FocusState private var isInputActive: Bool
    
    var body: some View {
        if isEditing {
            TextField("", text: $newValue, onCommit: {
                onCommit(newValue)
                isEditing = false
            })
            .focused($isInputActive)
            .labelsHidden()
        }
        else {
            Text(person.name)
                .onTapGesture {
                    if selection.contains(person.id), selection.count == 1 {
                        newValue = person.name
                        isEditing = true
                        isInputActive = true
                    }
                }
        }
    }
}

Right now, you need to tap on the row anywhere but on the text to select it. Then, if you tap on the text it'll go in edit mode.

Is there a way to let the list do its selection? I tried wrapping the tap gesture in simultaneousGesture but that didn't work.

Thanks!

This is super frustrating.

Happens in iOS 17 beta as well.

simultaneousGesture is supposed to solve this issue.

Made a radar for it: FB12683243

can confirm this happens on iOS 17.2 as well.

It seems like the issue is the lists built-in selection and swipe gestures interfere with any added custom gestures.

I have tried using high priority gestures, simultaneous gestures and just regular gestures and none of them seem to allow BOTH the list and the custom gestures to work simultaneously.

I have noticed this issue with quite a few of the UIKit backed swiftui features such as context menus, Lists, Forms, etc...

Maybe it's time that SwiftUI started to get native SwiftUI implementations of these features.

Allow custom tap gesture in List but maintain default selection gesture
 
 
Q