I'm trying use context menu with UIViewRepresentable. When context menu is activated, UIViewRepresentable disappears.
Here is the code:
UIViewRepresentable view:
struct TestView: UIViewRepresentable {
func makeUIView(context: Context) -> some UIView {
let view = UIView(frame: CGRect(x: 0, y: 0, width: 150, height: 150))
view.backgroundColor = UIColor.red
return view
}
func updateUIView(_ uiView: UIViewType, context: Context) {
//
}
}
ContentView:
struct ContentView: View {
var body: some View {
TestView()
.frame(width: 200, height: 200)
.contextMenu {
Text("Context Menu")
}
}
}
How to make UIViewRepresentable not disappear?