<commit_before>//
//  FOPopupAnimator.swift
//  Pods
//
//  Created by <NAME> on 2016-07-19.
//
//

class FOPopupAnimator: NSObject, UIViewControllerAnimatedTransitioning {
    
    var presenting = false
    var popup: FOPopup!
    
    convenience init(presenting: Bool, popup: FOPopup) {
        self.init()
        
        self.presenting = presenting
        self.popup = popup
    }
    
    func transitionDuration(transitionContext: UIViewControllerContextTransitioning?) -> NSTimeInterval {
        return 0.4
    }
    
    func animateTransition(transitionContext: UIViewControllerContextTransitioning) {
        if presenting {
            present(transitionContext)
        } else {
            dismiss(transitionContext)
        }
    }
    
    func present(transitionContext: UIViewControllerContextTransitioning) {
        if let
            from = transitionContext.viewControllerForKey(UITransitionContextFromViewControllerKey),
            to = transitionContext.viewControllerForKey(UITransitionContextToViewControllerKey)
        {
            let container = transitionContext.containerView()
        
            container.addSubview(popup.background)
            container.addSubview(to.view)
            
            to.view.addGestureRecognizer(panRecognizer(popup))
            popup.background.addGestureRecognizer(dismisRecognizer(popup))
            popup.background.addGestureRecognizer(panRecognizer(popup))
            popup.background.frame = from.view.bounds
            popup.background.backgroundColor = UIColor(white: 0, alpha: 1)
            popup.background.alpha = 0
            
            let toS = to.preferredContentSize
            to.view.frame = CGRect(x: (from.view.frame.width - toS.width) / 2.0, y: from.view.frame.height, width: toS.width, height: toS.height)
            
            UIView.animateWithDuration(transitionDuration(transitionContext), delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 0, options: .CurveEaseOut, animations: {
                [weak self] in
                self?.popup.background.alpha = 0.5
                
                if let anchor = (to as? FOPopupProtocol)?.startAnchorPoint {
                    to.view.frame = CGRect(x: (from.view.frame.width - toS.width) / 2.0, y: from.view.frame.height - anchor.y, width: toS.width, height: toS.height)
                } else {
                    to.view.frame = CGRect(x: (from.view.frame.width - toS.width) / 2.0, y: from.view.frame.height - toS.height, width: toS.width, height: toS.height)
                }
            }, completion: { (finished) in
                transitionContext.completeTransition(true)
            })
        }
    }
    
    func dismiss(transitionContext: UIViewControllerContextTransitioning) {
        if let
            from = transitionContext.viewControllerForKey(UITransitionContextFromViewControllerKey),
            to = transitionContext.viewControllerForKey(UITransitionContextToViewControllerKey)
        {<commit_msg>Modified for compatibility with swift 2.2 and 2.3<commit_after>//
//  FOPopupAnimator.swift
//  Pods
//
//  Created by <NAME> on 2016-07-19.
//
//

class FOPopupAnimator: NSObject, UIViewControllerAnimatedTransitioning {
    
    var presenting = false
    var popup: FOPopup!
    
    convenience init(presenting: Bool, popup: FOPopup) {
        self.init()
        
        self.presenting = presenting
        self.popup = popup
    }
    
    func transitionDuration(transitionContext: UIViewControllerContextTransitioning?) -> NSTimeInterval {
        return 0.4
    }
    
    func animateTransition(transitionContext: UIViewControllerContextTransitioning) {
        if presenting {
            present(transitionContext)
        } else {
            dismiss(transitionContext)
        }
    }
    
    func present(transitionContext: UIViewControllerContextTransitioning) {
        if let
            from = transitionContext.viewControllerForKey(UITransitionContextFromViewControllerKey),
            to = transitionContext.viewControllerForKey(UITransitionContextToViewControllerKey)
        {
            let container = transitionContext.containerView()
        
            container!.addSubview(popup.background)
            container!.addSubview(to.view)
            
            to.view.addGestureRecognizer(panRecognizer(popup))
            popup.background.addGestureRecognizer(dismisRecognizer(popup))
            popup.background.addGestureRecognizer(panRecognizer(popup))
            popup.background.frame = from.view.bounds
            popup.background.backgroundColor = UIColor(white: 0, alpha: 1)
            popup.background.alpha = 0
            
            let toS = to.preferredContentSize
            to.view.frame = CGRect(x: (from.view.frame.width - toS.width) / 2.0, y: from.view.frame.height, width: toS.width, height: toS.height)
            
            UIView.animateWithDuration(transitionDuration(transitionContext), delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 0, options: .CurveEaseOut, animations: {
                [weak self] in
                self?.popup.background.alpha = 0.5
                
                if let anchor = (to as? FOPopupProtocol)?.startAnchorPoint {
                    to.view.frame = CGRect(x: (from.view.frame.width - toS.width) / 2.0, y: from.view.frame.height - anchor.y, width: toS.width, height: toS.height)
                } else {
                    to.view.frame = CGRect(x: (from.view.frame.width - toS.width) / 2.0, y: from.view.frame.height - toS.height, width: toS.width, height: toS.height)
                }
            }, completion: { (finished) in
                transitionContext.completeTransition(true)
            })
        }
    }
    
    func dismiss(transitionContext: UIViewControllerContextTransitioning) {
        if let
            from = transitionContext.viewControllerForKey(UITransitionContextFromViewControllerKey),
            to = transitionContext.viewControllerForKey(UITransitionContextToViewControllerKey)
        {
{'fraction_non_alphanumeric': 0.09021810971579643, 'fraction_numerical': 0.008922670191672175, 'mean_word_length': 2.2613146551724137, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '4537762', 'n_tokens_mistral': 1742, 'n_tokens_neox': 1609, 'n_words': 289}