I'm building an app using mostly SwiftUI, but I have to use a UIKit ViewController to interface with PencilKit. I'm using UIViewControllerRepresentable
to interface between them.
So I have a ViewController which I'm using to set up the PencilKit part of my app, and inside it I have to set a PKToolPicker which depends on a UIResponder. To do so I have to write the following code:
canvasView = PKCanvasView(frame: view.bounds)
toolPicker.setVisible(true, forFirstResponder: canvasView)
canvasView.becomeFirstResponder()
This canvasView view I use here is the view which controls the drawing area, and you usually have to set it as a subview of the aforementioned ViewController. The issue is that in my case, this ViewController is nested inside a UIViewControllerRepresentable
which is nested inside a SwiftUI View. So, I need to add this SwiftUI view as a second FirstResponder or else the PKTool disappears each time I run a gesture on an SwiftUI view, as canvasView stops being first responder.
So my question is how do I do this? How can I set up a SwiftUI view as a first responder? Couldn't find how to obtain a SwiftUI's UIResponder object though so I could add it as a FirstResponder, anyone know how to?