I have a Button
in my View
that call a custom View Controller (UIViewControllerRepresentable
) because, the external library that I use, needs a view controller as parameter to show its own popups (and of course I cannot change).
For this reason I've created this middleware view controller but using this logic, the behaviour is not what i want...
Two popups, one on top of the other will be opened.
This because this library is not created thinking in SwiftUI, but the classic UIKit.
What I've done:
ContentView
struct ContentView: View {
@State var showViewController = false
var body: some View {
VStack(alignment: .leading, content: {
Button("SHOW VIEW CONTROLLER") {
showViewController.toggle()
}
})
.sheet(isPresented: $showViewController, content: {
EmptyViewController()
})
}
}
EmptyController:
struct EmptyViewController: UIViewControllerRepresentable {
func makeUIViewController(context: UIViewControllerRepresentableContext<EmptyViewController>) -> UIViewController {
let vc = UIViewController()
vc.view.backgroundColor = .systemRed
let extLibVC = ExternalLibraryClass()
extLibVC.doSomethingAndShowVC(from: vc) // issue here, because I need to pass VC
return vc
}
func updateUIViewController(_ uiViewController: UIViewController, context: UIViewControllerRepresentableContext<EmptyViewController>) {}
}
This is the result in this case:
There is a way to use directly the
let extLibVC = ExternalLibraryClass()
extLibVC.doSomethingAndShowVC(from: vc)
in the View
without passing from another view controller and avoid multiple popups?
Basically I don't want to see the RED View controller, but directly the GREEN one.