Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom NavigationController Delegate #25

Closed
felix-dumit opened this issue Jan 8, 2017 · 4 comments
Closed

Custom NavigationController Delegate #25

felix-dumit opened this issue Jan 8, 2017 · 4 comments

Comments

@felix-dumit
Copy link

I have a custom segue class that instantiates a UINavigationController class like this:

class CustomNavSegue: UIStoryboardSegue {

    override func perform() {
        let nav = ModalNavigationController(rootViewController: destination)
        nav.isHeroEnabled = true
        nav.modalPresentationStyle = .overCurrentContext
        source.present(nav, animated: true, completion: nil)
    }
}

In the ModalNavigationController viewDidLoad I set delegate = self since I need to perform a custom action on:

extension ModalNavigationController: UINavigationControllerDelegate {
    func navigationController(_ navigationController: UINavigationController,
                              willShow viewController: UIViewController,
                              animated: Bool) {
        //need to configure something on viewController.view
    }
}

However, when I set nav.isHeroEnabled I see that the navigationController's delegate gets set to Hero.shared.
Basically both need to be the delegate even though they need different method callbacks.

Do you have any ideas for solutions?
Maybe Hero could expose an extra navigationDelegate:UINavigationControllerDelegate property that only replays the callbacks it receives (probaby worth doing for other delegates as well).

@lkzhao
Copy link
Collaborator

lkzhao commented Jan 8, 2017

You can probably do something like this instead of setting isHeroEnabled.

extension ModalNavigationController: UINavigationControllerDelegate {
    func navigationController(_ navigationController: UINavigationController,
                              willShow viewController: UIViewController,
                              animated: Bool) {
        //need to configure something on viewController.view
    }

    func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationControllerOperation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        return Hero.shared.navigationController(navigationController, animationControllerFor:operation, from:fromVC)
    }
  
    func navigationController(_ navigationController: UINavigationController, interactionControllerFor animationController: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? {
        return Hero.shared.navigationController(navigationController, interactionControllerFor:animationController)
    }
}

@lkzhao
Copy link
Collaborator

lkzhao commented Jan 8, 2017

Hero.shared is not avaliable on cocoapods and carthage yet. The current master contains a major API change. Will wait a few day before releasing the next version. In the mean time, you can use

pod "Hero", :git => 'https://github.com/lkzhao/Hero.git'

@felix-dumit
Copy link
Author

felix-dumit commented Jan 8, 2017

I had to add nav.transitioningDelegate = Hero.shared instead of setting isHeroEnabled.
It turns out those two delegate methods are not being called at all. (even with setting isHeroEnabled) - is that expected?
EDIT: Actually it get's called once I push from the rootVC to the next one, that makes sense.

@lkzhao
Copy link
Collaborator

lkzhao commented Jan 8, 2017

Oh. I guess I didn't understand your question clearly.

Yes, for the modal presentation you only have to set 'transitionDelegate'. Hero also sets the navigation controller's delegate for animating navigation controller's child view controllers. If you don't need that functionality then it is ok to just set the 'transitionDelegate'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants