Skip to content

Instantly share code, notes, and snippets.

@trozware
Created November 1, 2021 04:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trozware/c702dad742455c1653ac8c45d5f9fc6e to your computer and use it in GitHub Desktop.
Save trozware/c702dad742455c1653ac8c45d5f9fc6e to your computer and use it in GitHub Desktop.
SwiftUI Mac double-clicking in list
import SwiftUI
struct ContentView: View {
@State private var selectedRow: Int?
@State private var resultText = ""
var body: some View {
VStack {
List(0 ..< 5, selection: $selectedRow) { item in
HStack {
Text("Row \(item)")
Spacer()
}
// almost invisible background to make full width clickable
.background(Color.white.opacity(0.01))
.onTapGesture(count: 2) {
selectedRow = item
resultText = "Double click on row \(item)"
}
.onTapGesture(count: 1) {
selectedRow = item
resultText = "Single click on row \(item)"
}
}
Text(resultText).padding()
}
.frame(width: 300, height: 300)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment