The app is still heavily using ViewControllers and TableViewControllers, which is making it difficult to integrate SwiftUI.
Firstly, I'm presenting a swiftUI view from a ViewController.
class SwiftUIViewController : UIViewController {
let contentView = UIHostingController(rootView: SwiftUIView())
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(contentView.view)
}
}
Now, from within my SwiftUIView, I need to start ViewControllers and TableViewControllers. I created an injector class that can be used with .sheet to present a view controller from SwiftUI.
struct ViewControllerInjector : UIViewControllerRepresentable {
let viewController: UIViewController
func makeUIViewController(context: Context) -> UIViewController {
return viewController
}
func updateUIViewController(_ uiViewController: UIViewController, context: Context) {
}
}
Now this kind of works, the only issue is that I can't seem to find a way to present the ViewController without it being a .sheet
struct SwiftUIView : View {
@State private var showingVC1 = false
...
.sheet(isPresented: $showingVC1) {
ViewControllerInjector(viewController: ViewController1())
}
...
}
I would like to completely leave the swift ui screen and continue with the view controller until I press the back button and return to the SwiftUI screen. Also, the injector doesn't seem to work with TableViewControllers even if I create a second injector class dedicated to TableView.
Is this type of navigation possible? If anything is not clear, don't hesitate to leave a comment. Thanks