I'm trying to implement a feature where I aim to open one VIPER module inside another VIPER module. But it only works if I use "dismiss", which I don't want to do. I'd like to be able to embed one VIPER module on top of another.
Here's my code:
VIPER 1 - ROUTER
@objc func openAnotherVC(_ notification: Notification) {
DispatchQueue.main.async {
//self.viewController?.dismiss(animated: true) // only works if I dismiss, I don't want to do that
self.goToAnotherVC()
}
}
func goToAnotherVC() {
guard let anotherVC = AnotherVCRouter.createModule().controller else { return }
self.viewController?.present(anotherVC, animated: true, completion: nil)
}
VIPER 2 - ROUTER
class AnotherVCRouter: AnotherVCRouterProtocol {
var controller: UIViewController?
static func createModule() -> AnotherVCRouterProtocol {
let router = AnotherVCRouter()
let view = AnotherVC(nibName: nil, bundle: nil)
let interactor = AnotherVCInteractor()
let presenter = AnotherVCPresenter(view: view, interactor: interactor, router: router)
let navController = UINavigationController(rootViewController: view)
navController.modalPresentationStyle = .custom
navController.navigationBar.isTranslucent = true
navController.navigationBar.shadowImage = UIImage()
navController.navigationBar.barTintColor = UIColor.white
router.controller = navController
return router
}
}
PROTOCOL
protocol AnotherVCRouterProtocol: AnyObject {
var controller: UIViewController? {get set}
static func createModule() ->AnotherVCRouterProtocol
}
Any help or suggestions on how to properly navigate between these VIPER modules without using "dismiss" would be greatly appreciated.