Looks like there's a problem when using the .contextMenu view modifier with nested views.
Here's sample code showing the problem:
import SwiftUI
enum SampleEnum: String, CaseIterable {
case one, two, three, four
}
struct ContentView: View {
var body: some View {
Form {
Section {
VStack {
HStack {
ForEach(SampleEnum.allCases, id:\.self) { id in
Text(id.rawValue)
.contextMenu {
Button {
print("Change country setting")
} label: {
Label("Choose Country", systemImage: "globe")
}
}
}
}
}
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
So, it doesn't appear that a context menu can be performed on a single Text view since the entire section/stack is selected.
Is there any way to get the contextMenu to work on an individual Text view in such a nested layout?


.contextMenuis deprecated