codytwinton / SwiftyVIPER

Swift Interaction with VIPER Architecture
MIT License
122 stars 14 forks source link

Examples of uses in UINavigationControllers and UITabBarController #16

Open elprl opened 5 years ago

elprl commented 5 years ago

Could the example project be updated with a use case for modules in UINavigationControllers and UITabBarControllers? Also, will you be doing a Swift 4.2 update?

elprl commented 5 years ago

Or a suggestion here on how to do it?

elprl commented 5 years ago

For others wondering about this, I ended up adding the following extension:

extension ModuleProtocol {

    func presentWithNavController(from fromVC: UIViewController?, style: UIModalTransitionStyle, completion: CodeBlock? = nil) {
        let navVC = UINavigationController(rootViewController: viewController)
        navVC.modalTransitionStyle = style
        fromVC?.present(navVC, animated: true, completion: completion)
    }

    func replaceRoot(from navController: UINavigationController?) {
        guard let navvy = navController else { return }
        var vcs = navvy.viewControllers
        vcs[vcs.count - 1] = viewController
        navvy.setViewControllers(vcs, animated: true)
    }
}

Which can then be used as follows: ProductDetailedModule().presentWithNavController(from: viewController, style: .coverVertical)

codytwinton commented 5 years ago

@elprl - Thanks for reaching out! I'll do my best to resolve this asap.

For now, I'm open to pull requests.