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

Animate transition between view controllers #58

Open
ranhsd opened this issue Mar 9, 2017 · 1 comment
Open

Animate transition between view controllers #58

ranhsd opened this issue Mar 9, 2017 · 1 comment

Comments

@ranhsd
Copy link

ranhsd commented Mar 9, 2017

Hi,
I am currently trying to refctor my app from MVVM to ReSwift. One of the things that i adopt is the ReSwiftRouter. The router allows me to navigate from one screen to another (either by push view controller into a navigation controller or by present it modally) .

I also consider to use Hero for animate transition between view controllers.
Hero created some extension to UIViewController which allows you to send a view controller there and animationType and then it will automatically animate the transition between both view controllers.
Now I wanted to know where is the best place to add this transition code? What i did now is to add it to the routable via the following lines of code:

` Hero.shared.setDefaultAnimationForNextTransition(.zoom)
Hero.shared.setContainerColorForNextTransition(.lightGray)

    let navigationController = UINavigationController.init(rootViewController: viewController)
    self.viewController.hero_replaceViewController(with: navigationController)
    
    return SignUpRoute(viewController)`

I am not sure that this is the best place or not to put the code.

What i was thinking is maybe to write an extension to Routable that will receive the source view controller and the destination view controller and animation type and this function will execute the animation.

Wanted to know what do you think or maybe there is a better solution?

Thanks.

@nitindhar7
Copy link

I was able to leverage Hero for this by presenting my viewcontrollers using modal presentation. Notice that I'm setting hero transition animations on both push and pop, which allows to me to have symmetry. For some reason, using Hero's navigationAnimationType wasn't working, which is why I chose modal presentation, otherwise I would've stuck to show.

class MainRoutable: Routable {
    
    let viewController: UIViewController
    
    init(_ viewController: UIViewController) {
        self.viewController = viewController
    }
    
    func pushRouteSegment(
        _ routeElementIdentifier: RouteElementIdentifier,
        animated: Bool,
        completionHandler: @escaping RoutingCompletionHandler) -> Routable {
        if routeElementIdentifier == "UsersRoute" {
            let userViewController = storyboard.instantiateViewController(withIdentifier: "UsersViewController")
            userViewController.hero.modalAnimationType = .zoom
            (self.viewController as! UINavigationController)
                .childViewControllers
                .first?
                .present(userViewController, animated: true, completion: completionHandler)
            
            return UsersRoutable()
        }
        
        fatalError("Cannot handle this route change!")
    }
    
    func popRouteSegment(
        _ routeElementIdentifier: RouteElementIdentifier,
        animated: Bool,
        completionHandler: @escaping RoutingCompletionHandler) {
        print("hello")
        if routeElementIdentifier == "UsersViewController" {
            (self.viewController as! UINavigationController).visibleViewController?.hero.modalAnimationType = .zoomOut
        }
        self.viewController.dismiss(animated: true, completion: completionHandler)
    }
}

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