I had the same problem in a NavigationSplitView and managed to solve it using simultaneous gestures as you originally tried. To make sure single-clicking fully matches native behaviour, my single-click handler sets the selection which is passed as a binding to the List, and it also sets a FocusState.
struct ContentView: View {
// Assume there's an "items" array of Item instances to display.
@State private var selectedItem: Item?
@FocusState var listFocused: Bool
var body: some View {
NavigationSplitView {
List(selection: $selectedItem) {
ForEach(items) { item in
NavigationLink(value: item) { Text(verbatim: item.name) }
.gesture(doubleClickGesture(for: item))
}
}
.focused($listFocused)
} detail: {
DetailView(item)
}
}
private func doubleClickGesture(for item: Item) -> some Gesture {
SimultaneousGesture(
TapGesture(count: 1).onEnded {
selectedItem = item
listFocused = true
},
TapGesture(count: 2).onEnded {
print(“Double-clicked”)
}
)
}
}
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: