Priva28 / HostingPassthrough

Let SwiftUI and UIKit views live in harmony.
MIT License
86 stars 2 forks source link

Could you add an example? #4

Open erksch opened 8 months ago

erksch commented 8 months ago

Hey there!

The premise of this component sounds like what I am looking for (getting touches through a UIHostingController) but I do not understand how to use HostingParentController. Where do I pass my SwiftUI View?

In the screenshot in the README you initialize some UIHostingControllers but it is not clear where the variables are used. It would be helpful to have some more example code in the README :)

erksch commented 8 months ago

Ok, I got it :) Probably looks something like this:

class SeniorCareSpeechUIViewController: HostingParentController {
    let hostingController = UIHostingController(rootView: MySwiftUIView)

    override func viewDidLoad() {
        super.viewDidLoad()

        addChild(hostingController)
        view.addSubview(hostingController.view)
        hostingController.didMove(toParent: self)
    }
}