UIMenuController broken in SwiftUI iOS 13.5

Trying to modify the UIMenuController and I am no longer able to do so in a iOS 13.5 SwiftUI project.

Code Block
import SwiftUI
struct ContentView: View {
var body: some View {
MyTextViewRepresentable()
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
struct MyTextViewRepresentable: UIViewRepresentable {
func makeUIView(context: Context) -> MyTextView {
let textView = MyTextView()
textView.text = "Double click on me in order to test. I am not supposed to display any menu options because my canPerformAction() is returning false. I am work just fine in a Storyboard."
textView.isEditable = false
return textView
}
func makeCoordinator() -> Coordinator {
Coordinator()
}
func updateUIView(_ uiView: MyTextView, context: Context) { }
}
class MyTextView: UITextView {
override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
return false // Remove all menu options
}
}


The code below works fine in a Storyboard project.
Code Block
import UIKit
class ViewController: UIViewController, UITextViewDelegate {
    fileprivate func createTextView() {
        let textView = MyTextView(frame: CGRect(x: 0, y: 50, width: 500, height: 100))
        textView.text = "Double click on some text. I am not supposed to display any menu options because my canPerformAction() is returning false. I am working fine because I was built by only importing UIKit inside of my Storyboard project."
        textView.isEditable = false
        view.addSubview(textView)
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        createTextView()
    }
}
class MyTextView: UITextView {
    override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
        return false
    }
}


I noticed the same:
  • no menu in iOS 13.3 simulator,

  • in iOS 13.5, menu shows with 4 items "Select To Here", "Look Up", "Learn…" and "Share…" But they are all effectively disabled.

Could you test with Xcode 11.6 or better 12 ?

I have a similar problem using the same technique.
I just need the "paste:" option to appear. The other items flood the menu and are not needed in the context I require.
I am interested in any solution for this.
As of XCode 12.0 it seems to be OK
UIMenuController broken in SwiftUI iOS 13.5
 
 
Q