.contextMenu {} is not working for me in my tvOS app.
It is supported in tvOS 14
https://developer.apple.com/documentation/swiftui/view/contextmenu(menuitems:)
Someone an idea how to get it working?
Example
Full project: https://github.com/l1ghthouse/TVContextMenu
It is supported in tvOS 14
https://developer.apple.com/documentation/swiftui/view/contextmenu(menuitems:)
Someone an idea how to get it working?
Example
Code Block Swift import SwiftUI struct NumberItem: Identifiable, Hashable { var id = UUID() var number: String } struct ContentView: View { let array: [NumberItem] = [NumberItem(number: "423"), NumberItem(number: "645"), NumberItem(number: "213"), NumberItem(number: "975"), NumberItem(number: "357"), NumberItem(number: "950"), NumberItem(number: "043"), NumberItem(number: "174")] let columns = [GridItem(.adaptive(minimum: 300.0, maximum: 800.0))] var body: some View { ScrollView { LazyVGrid(columns: columns, spacing: 20) { ForEach(array, id: \.id) { item in ItemView(item: item) .contentShape(RoundedRectangle(cornerRadius: 12, style: .continuous)) .contextMenu { // Edit Button(action: { print("Edit") }) { Text("Edit") Image(systemName: "square.and.pencil") } // Delete Button(action: { print("Delete") }) { Text("Delete") Image(systemName: "trash") } } } } } } } struct ItemView: View { @State private var focused: Bool = false @State var item: NumberItem var body: some View { Group { Text("Item \(item.number)") .padding() } .padding() .background(Color.pink) .cornerRadius(12) .scaleEffect(self.focused ? 1.20 : 1.00) .shadow(radius: 10) .focusable(true) { isFocused in withAnimation(.easeInOut(duration:0.3)) { self.focused = isFocused } } } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } }
Full project: https://github.com/l1ghthouse/TVContextMenu