<commit_before>//
//  CascadePresenter.swift
//  Pods
//
//  Created by <NAME> on 2/3/17.
//
//

import UIKit

class CascadePresenter: CascadeAbstractAnimator {
    override func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
        guard let fromVC = transitionContext.viewController(forKey: .from),
            let toVC = transitionContext.viewController(forKey: .to),
            let toSnapshot = toVC.view.snapshotView(afterScreenUpdates: true),
            let fromSnapshot = fromVC.view.snapshotView(afterScreenUpdates: true) else {
                transitionContext.completeTransition(false)
                return
        }
        
        let containerView = transitionContext.containerView
        
        toSnapshot.frame = self.initialFrame
        
        setupFromSnapshot(fromSnapshot: fromSnapshot)
        updateFromVCFrame(from: fromSnapshot)
        
        containerView.addSubview(toVC.view)
        containerView.addSubview(toSnapshot)
        
        toVC.view.frame = self.finalFrame
        toVC.view.round(corners: [.topLeft, .topRight], radius: parameters.cornerRadius)
        toVC.view.isHidden = true
        
        UIView.animate(withDuration: transitionDuration(using: transitionContext), animations: {
            toSnapshot.frame = self.finalFrame
            toSnapshot.round(corners: [.topLeft, .topRight], radius: self.parameters.cornerRadius)
            
            fromVC.view.transform = CGAffineTransform(scaleX: self.parameters.scale, y: self.parameters.scale)
            fromVC.view.alpha = self.parameters.presentingVCAlpha
            fromVC.view.layer.cornerRadius = self.parameters.cornerRadius
            self.updateFromVCFrame(from: fromVC.view)
        }) { (completed) in
            containerView.insertSubview(fromSnapshot, at: 0)
            toSnapshot.removeFromSuperview()
            
            toVC.view.isHidden = false
            
            transitionContext.completeTransition(completed)
        }
    }
}

// MARK: - Private methods
extension CascadePresenter {
    fileprivate var initialFrame: CGRect {
        var frame = UIScreen.main.bounds
        frame.size.height -= parameters.presentedTopMargin
        frame.origin.y = UIScreen.main.bounds.height
        return frame
    }
    
    fileprivate var finalFrame: CGRect {
        var finalFrame = initialFrame
        finalFrame.origin.y = parameters.presentedTopMargin
        return finalFrame
    }
    
    fileprivate func updateFromVCFrame(from: UIView) {
        var frame = from.frame
        frame.origin.y = parameters.presentingTopMargin
        from.frame = frame
    }
    
    fileprivate func setupFromSnapshot(fromSnapshot: UIView) {
        fromSnapshot.transform = CGAffineTransform(scaleX: parameters.scale, y: parameters.scale)
        fromSnapshot.alpha = parameters.presentingVCAlpha
        fromSnapshot.layer.cornerRadius = parameters.cornerRadius
        fromSnapshot.layer.masksToBounds = true
        fromSnapshot.tag = parameters.viewTag
    }
}
<commit_msg>added background color changing<commit_after>//
//  CascadePresenter.swift
//  Pods
//
//  Created by <NAME> on 2/3/17.
//
//

import UIKit

class CascadePresenter: CascadeAbstractAnimator {
    override func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
        guard let fromVC = transitionContext.viewController(forKey: .from),
            let toVC = transitionContext.viewController(forKey: .to),
            let toSnapshot = toVC.view.snapshotView(afterScreenUpdates: true),
            let fromSnapshot = fromVC.view.snapshotView(afterScreenUpdates: true) else {
                transitionContext.completeTransition(false)
                return
        }
        
        let containerView = transitionContext.containerView
        containerView.backgroundColor = parameters.backgroundColor
        
        toSnapshot.frame = self.initialFrame
        
        setupFromSnapshot(fromSnapshot: fromSnapshot)
        updateFromVCFrame(from: fromSnapshot)
        
        containerView.addSubview(toVC.view)
        containerView.addSubview(toSnapshot)
        
        toVC.view.frame = self.finalFrame
        toVC.view.round(corners: [.topLeft, .topRight], radius: parameters.cornerRadius)
        toVC.view.isHidden = true
        
        UIView.animate(withDuration: transitionDuration(using: transitionContext), animations: {
            toSnapshot.frame = self.finalFrame
            toSnapshot.round(corners: [.topLeft, .topRight], radius: self.parameters.cornerRadius)
            
            fromVC.view.transform = CGAffineTransform(scaleX: self.parameters.scale, y: self.parameters.scale)
            fromVC.view.alpha = self.parameters.presentingVCAlpha
            fromVC.view.layer.cornerRadius = self.parameters.cornerRadius
            self.updateFromVCFrame(from: fromVC.view)
        }) { (completed) in
            containerView.insertSubview(fromSnapshot, at: 0)
            toSnapshot.removeFromSuperview()
            
            toVC.view.isHidden = false
            
            transitionContext.completeTransition(completed)
        }
    }
}

// MARK: - Private methods
extension CascadePresenter {
    fileprivate var initialFrame: CGRect {
        var frame = UIScreen.main.bounds
        frame.size.height -= parameters.presentedTopMargin
        frame.origin.y = UIScreen.main.bounds.height
        return frame
    }
    
    fileprivate var finalFrame: CGRect {
        var finalFrame = initialFrame
        finalFrame.origin.y = parameters.presentedTopMargin
        return finalFrame
    }
    
    fileprivate func updateFromVCFrame(from: UIView) {
        var frame = from.frame
        frame.origin.y = parameters.presentingTopMargin
        from.frame = frame
    }
    
    fileprivate func setupFromSnapshot(fromSnapshot: UIView) {
        fromSnapshot.transform = CGAffineTransform(scaleX: parameters.scale, y: parameters.scale)
        fromSnapshot.alpha = parameters.presentingVCAlpha
        fromSnapshot.layer.cornerRadius = parameters.cornerRadius
        fromSnapshot.layer.masksToBounds = true
        fromSnapshot.tag = parameters.viewTag
    }
}

{'fraction_non_alphanumeric': 0.07945205479452055, 'fraction_numerical': 0.0016116035455278, 'mean_word_length': 2.4884766722878022, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '7142238', 'n_tokens_mistral': 1656, 'n_tokens_neox': 1619, 'n_words': 297}