<commit_before>//
//  Navigator.swift
//  Union
//
//  Created by <NAME> on 10/7/15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import UIKit

public class Navigator: NSObject {

    let before = AnimationManager()
    let present = AnimationManager()

    var duration: NSTimeInterval {
        return before.duration + present.duration
    }

    func animate(transitionContext: UIViewControllerContextTransitioning) {
        setup(transitionContext)
        start(transitionContext)
    }

    public class func animate() -> UIViewControllerAnimatedTransitioning {
        return Navigator()
    }
}

extension Navigator: UIViewControllerAnimatedTransitioning {

    public func animateTransition(transitionContext: UIViewControllerContextTransitioning) {
        animate(transitionContext)
    }

    public func transitionDuration(transitionContext: UIViewControllerContextTransitioning?) -> NSTimeInterval {
        return duration
    }
}

extension Navigator {

    func setup(transitionContext: UIViewControllerContextTransitioning) {
        let fromViewController = transitionContext.viewControllerForKey(UITransitionContextFromViewControllerKey)
        let toViewController = transitionContext.viewControllerForKey(UITransitionContextToViewControllerKey)

        if let fromViewController = fromViewController, let toViewController = toViewController {
            _setup(fromViewController: fromViewController, toViewController: toViewController)
        }
    }

    func start(transitionContext: UIViewControllerContextTransitioning) {
        before.completion = { [unowned self] in
            self.startTransition(transitionContext)
        }
        before.start()
    }

    func startTransition(transitionContext: UIViewControllerContextTransitioning) {

        if let fromView = transitionContext.viewForKey(UITransitionContextFromViewKey), let toView = transitionContext.viewForKey(UITransitionContextToViewKey) {
            toView.frame = fromView.frame
            transitionContext.containerView()?.insertSubview(toView, aboveSubview: fromView)
        }

        present.completion = {
            let fromView = transitionContext.viewForKey(UITransitionContextFromViewKey)
            fromView?.removeFromSuperview()
            transitionContext.completeTransition(true)
        }
        present.start()
    }


    private func _setup(fromViewController fromViewController: UIViewController, toViewController: UIViewController) {

        if let delegate = fromViewController as? Delegate {
            before.animations = delegate.animationsBeforeTransitionTo(toViewController)
        }

        // present
        var fromAnimations: [Animation] = []
        if let delegate = fromViewController as? Delegate {
            fromAnimations = delegate.animationsBeforeTransitionTo(toViewController)
        }
        var toAnimation: [Animation] = []
        if let delegate = toViewController as? Delegate {
            toAnimation = delegate.animationsDuringTransitionFrom(fromViewController)
        }
        
        present.animations = fromAnimations + toAnimation
    }
}<commit_msg>oops!<commit_after>//
//  Navigator.swift
//  Union
//
//  Created by <NAME> on 10/7/15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import UIKit

public class Navigator: NSObject {

    let before = AnimationManager()
    let present = AnimationManager()

    var duration: NSTimeInterval {
        return before.duration + present.duration
    }

    func animate(transitionContext: UIViewControllerContextTransitioning) {
        setup(transitionContext)
        start(transitionContext)
    }

    public class func animate() -> UIViewControllerAnimatedTransitioning {
        return Navigator()
    }
}

extension Navigator: UIViewControllerAnimatedTransitioning {

    public func animateTransition(transitionContext: UIViewControllerContextTransitioning) {
        animate(transitionContext)
    }

    public func transitionDuration(transitionContext: UIViewControllerContextTransitioning?) -> NSTimeInterval {
        return duration
    }
}

extension Navigator {

    func setup(transitionContext: UIViewControllerContextTransitioning) {
        let fromViewController = transitionContext.viewControllerForKey(UITransitionContextFromViewControllerKey)
        let toViewController = transitionContext.viewControllerForKey(UITransitionContextToViewControllerKey)

        if let fromViewController = fromViewController, let toViewController = toViewController {
            _setup(fromViewController: fromViewController, toViewController: toViewController)
        }
    }

    func start(transitionContext: UIViewControllerContextTransitioning) {
        before.completion = { [unowned self] in
            self.startTransition(transitionContext)
        }
        before.start()
    }

    func startTransition(transitionContext: UIViewControllerContextTransitioning) {

        if let fromView = transitionContext.viewForKey(UITransitionContextFromViewKey), let toView = transitionContext.viewForKey(UITransitionContextToViewKey) {
            toView.frame = fromView.frame
            transitionContext.containerView()?.insertSubview(toView, aboveSubview: fromView)
        }

        present.completion = {
            let fromView = transitionContext.viewForKey(UITransitionContextFromViewKey)
            fromView?.removeFromSuperview()
            transitionContext.completeTransition(true)
        }
        present.start()
    }


    private func _setup(fromViewController fromViewController: UIViewController, toViewController: UIViewController) {

        if let delegate = fromViewController as? Delegate {
            before.animations = delegate.animationsBeforeTransitionTo(toViewController)
        }

        // present
        var fromAnimations: [Animation] = []
        if let delegate = fromViewController as? Delegate {
            fromAnimations = delegate.animationsDuringTransitionFrom(toViewController)
        }
        var toAnimation: [Animation] = []
        if let delegate = toViewController as? Delegate {
            toAnimation = delegate.animationsDuringTransitionFrom(fromViewController)
        }
        
        present.animations = fromAnimations + toAnimation
    }
}
{'fraction_non_alphanumeric': 0.06876196553924697, 'fraction_numerical': 0.002871729419272495, 'mean_word_length': 3.296778615490062, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4293327', 'n_tokens_mistral': 1584, 'n_tokens_neox': 1427, 'n_words': 308}