Skip to content

Instantly share code, notes, and snippets.

@sturdysturge
Last active July 21, 2020 02:11
Show Gist options
  • Save sturdysturge/bc51f8d4acd437c23cfbf67403f7059d to your computer and use it in GitHub Desktop.
Save sturdysturge/bc51f8d4acd437c23cfbf67403f7059d to your computer and use it in GitHub Desktop.
RevDoc ContextMenu
import SwiftUI
struct ContentView: View {
@State var selectedIndex = -1
var selection: String {
switch selectedIndex {
case 0: return "♥️"
case 1: return "♣️"
case 2: return "♠️"
case 3: return "♦️"
default: return ""
}
}
var body: some View {
VStack {
Text("Favourite card suit:")
Text(selection)
.font(.system(size: 200))
.focusable()
.padding()
.contextMenu {
Button("♥️ - Hearts") {selectedIndex = 0}
Button("♣️ - Clubs") {selectedIndex = 1}
Button("♠️ - Spades") {selectedIndex = 2}
Button("♦️ - Diamonds") {selectedIndex = 3}
}
Text("Long press to make a choice")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment