I am presenting and dismissing a swiftUI view with a button, and it works fine.
The swiftUI view:
struct SmartG_SwiftUI: View {
var dismissAction: (() -> Void)
var body: some View {
Button(action: {
dismissAction()
}) {}
}
}
I am presenting the SwiftUI view controller from UIKit, this way:
let hostingVC = UIHostingVC(rootView: SmartG_SwiftUI(dismissAction: {
vc?.dismiss( animated: true, completion: nil )
}))
vc?.present(hostingVC, animated: true, completion: nil)
My question is, how could I put this button in a separate struct? So in order to have something like:
struct SmartG_SwiftUI: View {
var dismissAction: (() -> Void)
Header()
}
struct Header: View {
Button(action: {
dismissAction() //unknown here
}) {}
}