Created
November 1, 2021 04:28
-
-
Save trozware/c702dad742455c1653ac8c45d5f9fc6e to your computer and use it in GitHub Desktop.
SwiftUI Mac double-clicking in list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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