I use UIHostingController inside my UIViewController to present a SwiftUI View. I have a button in that view which I want to tap and dismiss the presented view. How do I dimiss SwiftUI views when presented in a UIHostingController
...{
let vc = UIHostingController(rootView: SwiftUIView())
present(vc, animated: true, completion: nil)
}
struct SwiftUIView : View {
var body: some View {
CustomButton()
}
}
struct CustomButton: View {
var body: some View {
Button(action: {
self.buttonAction()
}) {
Text(buttonTitle)
}
}
func buttonAction(){
//dismiss the SwiftUIView when this button pressed
}
}