<commit_before>//
//  SpringView.swift
//  DesignerNewsApp
//
//  Created by <NAME> on 2015-01-01.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

import UIKit

@IBDesignable class SpringView: UIView {
    
    @IBInspectable var animation: String = ""
    
    func animatePreset() {
        isFrom = true
        reset()
        
        switch animation {
        case "slideLeft":
            x = 300*force
        case "slideRight":
            x = -300*force
        case "slideDown":
            y = -300*force
        case "slideUp":
            y = 300*force
        case "fadeIn":
            opacity = 0
        case "fadeOut":
            isFrom = false
            opacity = 0
        case "fadeLeft":
            opacity = 0
            x = 300*force
        case "fadeInRight":
            x = -300*force
            opacity = 0
        case "fadeInDown":
            y = -300*force
            opacity = 0
        case "fadeInUp":
            y = 300*force
            opacity = 0
        case "zoomIn":
            opacity = 0
            scaleX = 2*force
            scaleY = 2*force
        case "zoomOut":
            isFrom = false
            opacity = 0
            scaleX = 2*force
            scaleY = 2*force
        case "shake":
            let animation = CAKeyframeAnimation()
            animation.keyPath = "position.x"
            animation.values = [0, 30*force, -30*force, 30*force, 0]
            animation.keyTimes = [0, 0.2, 0.4, 0.6, 0.8, 1]
            animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionDefault)
            animation.duration = CFTimeInterval(duration)
            animation.additive = true
            layer.addAnimation(animation, forKey: "shake")
            opacity = 0.99
        case "pop":
            let animation = CAKeyframeAnimation()
            animation.keyPath = "transform.scale"
            animation.values = [0, 0.1*force, -0.1*force, 0.1*force, 0]
            animation.keyTimes = [0, 0.2, 0.4, 0.6, 0.8, 1]
            animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionDefault)
            animation.duration = CFTimeInterval(duration)
            animation.additive = true
            layer.addAnimation(animation, forKey: "pop")
            opacity = 0.99
        case "morph":
            let morphX = CAKeyframeAnimation()
            morphX.keyPath = "transform.scale.x"
            morphX.values = [1, 1.1*force, 0.9, 1.1*force, 1]
            morphX.keyTimes = [0, 0.2, 0.4, 0.6, 0.8, 1]
            morphX.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionDefault)
            morphX.duration = CFTimeInterval(duration)
            layer.addAnimation(morphX, forKey: "morphX")
            
            let morphY = CAKeyframeAnimation()
            morphY.keyPath = "transform.scale.y"
            morphY.values = [1, 0.9, 1.1*force, 0.9, 1]
            morphY.keyTimes = [0, 0.2, 0.4, 0.6, 0.8, 1]
            morphY.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionDefault)
            morphY.duration = CFTimeInterval(duration)
            layer.addAnimation(morphY, forKey: "morphY")

            opacity = 0.99
        case "flash":
            let animation = CAKeyframeAnimation()
            animation.keyPath = "opacity"
            animation.values = [1, 0, 1, 0, 1]
            animation.keyTimes = [0, 0.2, 0.4, 0.6, 0.8, 1]
            animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionDefault)
            animation.duration = CFTimeInterval(duration)
            animation.additive = true
            layer.addAnimation(animation, forKey: "flash")
            opacity = 0.99
        default:
            x = 300
        }
    }
    
    @IBInspectable var force: CGFloat = 1
    @IBInspectable var x: CGFloat = 0
    @IBInspectable var y: CGFloat = 0
    @IBInspectable var scaleX: CGFloat = 1
    @IBInspectable var scaleY: CGFloat = 1
    @IBInspectable var rotate: CGFloat = 0
    @IBInspectable var opacity: CGFloat = 1
    @IBInspectable var delay: CGFloat = 0
    @IBInspectable var duration: CGFloat = 0.7
    @IBInspectable var damping: CGFloat = 0.7
    @IBInspectable var velocity: CGFloat = 0.7
    @IBInspectable var isFrom: Bool = false
    
    func animate() {
        isFrom = false
        animatePreset()
        setView {}
    }
    
    func animateFrom() {
        isFrom = true
        setView {}
    }
    
    func animateNext(completion: () -> ()) {
        animatePreset()
        setView {
            completion()
        }
    }
    
    override func awakeFromNib() {
        animatePreset()
        setView {}
    }
    
    private func setView(completion: () -> ()) {
        if isFrom {
            let translate = CGAffineTransformMakeTranslation(self.x, self.y)
            let scale = CGAffineTransformMakeScale(self.scaleX, self.scaleY)
            let rotate = CGAffineTransformMakeRotation(self.rotate)
            let translateAndScale = CGAffineTransformConcat(translate, scale)
            self.transform = CGAffineTransformConcat(rotate, translateAndScale)
            
            self.alpha = self.opacity
        }
        
        UIView.animateWithDuration( NSTimeInterval(duration),
            delay: NSTimeInterval(delay),
            usingSpringWithDamping: damping,
            initialSpringVelocity: velocity,
            options: nil,
            animations: {
                
            if self.isFrom {
                self.transform = CGAffineTransformIdentity
                self.alpha = 1
            }
            else {
                let translate = CGAffineTransformMakeTranslation(self.x, self.y)
                let scale = CGAffineTransformMakeScale(self.scaleX, self.scaleY)
                let rotate = CGAffineTransformMakeRotation(self.rotate)
                let translateAndScale = CGAffineTransformConcat(translate, scale)
                self.transform = CGAffineTransformConcat(rotate, translateAndScale)
                
                self.alpha = self.opacity
            }
                
        }, { finished in
            
            completion()
            
        })
    }
    
    func reset() {
        x = 0
        y = 0
        scaleX = 1
        scaleY = 1
        rotate = 0
        opacity = 1
        delay = 0
        duration = 0.7
        damping = 0.7
        velocity = 0.7
    }
}<commit_msg>squeeze, flash, wobble, swing<commit_after>//
//  SpringView.swift
//  DesignerNewsApp
//
//  Created by <NAME> on 2015-01-01.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

import UIKit

@IBDesignable class SpringView: UIView {
    
    @IBInspectable var animation: String = ""
    
    func animatePreset() {
        isFrom = true
        reset()
        
        switch animation {
        case "slideLeft":
            x = 300*force
        case "slideRight":
            x = -300*force
        case "slideDown":
            y = -300*force
        case "slideUp":
            y = 300*force
        case "fadeIn":
            opacity = 0
        case "fadeOut":
            isFrom = false
            opacity = 0
        case "fadeLeft":
            opacity = 0
            x = 300*force
        case "fadeInRight":
            x = -300*force
            opacity = 0
        case "fadeInDown":
            y = -300*force
            opacity = 0
        case "fadeInUp":
            y = 300*force
            opacity = 0
        case "zoomIn":
            opacity = 0
            scaleX = 2*force
            scaleY = 2*force
        case "zoomOut":
            isFrom = false
            opacity = 0
            scaleX = 2*force
            scaleY = 2*force
        case "shake":
            let animation = CAKeyframeAnimation()
            animation.keyPath = "position.x"
            animation.values = [0, 30*force, -30*force, 30*force, 0]
            animation.keyTimes = [0, 0.2, 0.4, 0.6, 0.8, 1]
            animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
            animation.duration = CFTimeInterval(duration)
            animation.additive = true
            animation.repeatCount = 1
            animation.beginTime = CACurrentMediaTime() + CFTimeInterval(delay)
            layer.addAnimation(animation, forKey: "shake")
            opacity = 0.99
        case "pop":
            let animation = CAKeyframeAnimation()
            animation.keyPath = "transform.scale"
            animation.values = [0, 0.1*force, -0.1*force, 0.1*force, 0]
            animation.keyTimes = [0, 0.2, 0.4, 0.6, 0.8, 1]
            animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionDefault)
            animation.duration = CFTimeInterval(duration)
            animation.additive = true
            animation.repeatCount = 1
            animation.beginTime = CACurrentMediaTime() + CFTimeInterval(delay)
            layer.addAnimation(animation, forKey: "pop")
            opacity = 0.99
        case "morph":
            let morphX = CAKeyframeAnimation()
            morphX.keyPath = "transform.scale.x"
            morphX.values = [1, 1.1*force, 0.9, 1.1*force, 1]
            morphX.keyTimes = [0, 0.2, 0.4, 0.6, 0.8, 1]
            morphX.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionDefault)
            morphX.duration = CFTimeInterval(duration)
            morphX.repeatCount = 1
            morphX.beginTime = CACurrentMediaTime() + CFTimeInterval(delay)
            layer.addAnimation(morphX, forKey: "morphX")
            
            let morphY = CAKeyframeAnimation()
            morphY.keyPath = "transform.scale.y"
            morphY.values = [1, 0.9, 1.1*force, 0.9, 1]
            morphY.keyTimes = [0, 0.2, 0.4, 0.6, 0.8, 1]
            morphY.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionDefault)
            morphY.duration = CFTimeInterval(duration)
            morphY.repeatCount = 1
            morphY.beginTime = CACurrentMediaTime() + CFTimeInterval(delay)
            layer.addAnimation(morphY, forKey: "morphY")

            opacity = 0.99
        case "squeeze":
            let morphX = CAKeyframeAnimation()
            morphX.keyPath = "transform.scale.x"
            morphX.values = [1, 1.5*force, 0.5, 1.5*force, 1]
            morphX.keyTimes = [0, 0.2, 0.4, 0.6, 0.8, 1]
            morphX.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionDefault)
            morphX.duration = CFTimeInterval(duration)
            morphX.repeatCount = 1
            morphX.beginTime = CACurrentMediaTime() + CFTimeInterval(delay)
            layer.addAnimation(morphX, forKey: "morphX")
            
            let morphY = CAKeyframeAnimation()
            morphY.keyPath = "transform.scale.y"
            morphY.values = [1, 0.5, 1, 0.5, 1]
            morphY.keyTimes = [0, 0.2, 0.4, 0.6, 0.8, 1]
            morphY.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionDefault)
            morphY.duration = CFTimeInterval(duration)
            morphY.repeatCount = 1
            morphY.beginTime = CACurrentMediaTime() + CFTimeInterval(delay)
            layer.addAnimation(morphY, forKey: "morphY")
            
            opacity = 0.99
        case "flash":
            let animation = CABasicAnimation()
            animation.keyPath = "opacity"
            animation.fromValue = 1
            animation.toValue = 0
            animation.duration = CFTimeInterval(duration)
            animation.repeatCount = 2
            animation.autoreverses = true
            animation.beginTime = CACurrentMediaTime() + CFTimeInterval(delay)
            layer.addAnimation(animation, forKey: "flash")
            opacity = 0.99
        case "wobble":
            let animation = CAKeyframeAnimation()
            animation.keyPath = "transform.rotation"
            animation.values = [0, 0.2*force, -0.2*force, 0.2*force, 0]
            animation.keyTimes = [0, 0.2, 0.4, 0.6, 0.8, 1]
            animation.duration = CFTimeInterval(duration)
            animation.additive = true
            animation.beginTime = CACurrentMediaTime() + CFTimeInterval(delay)
            layer.addAnimation(animation, forKey: "wobble")
            
            let x = CAKeyframeAnimation()
            x.keyPath = "position.x"
            x.values = [0, 30*force, -30*force, 30*force, 0]
            x.keyTimes = [0, 0.2, 0.4, 0.6, 0.8, 1]
            x.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
            x.duration = CFTimeInterval(duration)
            x.additive = true
            x.repeatCount = 1
            x.beginTime = CACurrentMediaTime() + CFTimeInterval(delay)
            layer.addAnimation(x, forKey: "x")
            
            opacity = 0.99
        case "swing":
            let animation = CAKeyframeAnimation()
            animation.keyPath = "transform.rotation"
            animation.values = [0, 0.2*force, -0.2*force, 0.2*force, 0]
            animation.keyTimes = [0, 0.2, 0.4, 0.6, 0.8, 1]
            animation.duration = CFTimeInterval(duration)
            animation.additive = true
            animation.beginTime = CACurrentMediaTime() + CFTimeInterval(delay)
            layer.addAnimation(animation, forKey: "swing")
        default:
            x = 300
        }
    }
    
    @IBInspectable var force: CGFloat = 1
    @IBInspectable var delay: CGFloat = 0
    @IBInspectable var duration: CGFloat = 0.7
    @IBInspectable var damping: CGFloat = 0.7
    @IBInspectable var velocity: CGFloat = 0.7
    @IBInspectable var x: CGFloat = 0
    @IBInspectable var y: CGFloat = 0
    @IBInspectable var scaleX: CGFloat = 1
    @IBInspectable var scaleY: CGFloat = 1
    @IBInspectable var rotate: CGFloat = 0
    @IBInspectable var opacity: CGFloat = 1
    @IBInspectable var isFrom: Bool = false
    
    func animate() {
        isFrom = false
        animatePreset()
        setView {}
    }
    
    func animateFrom() {
        isFrom = true
        setView {}
    }
    
    func animateNext(completion: () -> ()) {
        animatePreset()
        setView {
            completion()
        }
    }
    
    override func awakeFromNib() {
        animatePreset()
        setView {}
    }
    
    private func setView(completion: () -> ()) {
        if isFrom {
            let translate = CGAffineTransformMakeTranslation(self.x, self.y)
            let scale = CGAffineTransformMakeScale(self.scaleX, self.scaleY)
            let rotate = CGAffineTransformMakeRotation(self.rotate)
            let translateAndScale = CGAffineTransformConcat(translate, scale)
            self.transform = CGAffineTransformConcat(rotate, translateAndScale)
            
            self.alpha = self.opacity
        }
        
        UIView.animateWithDuration( NSTimeInterval(duration),
            delay: NSTimeInterval(delay),
            usingSpringWithDamping: damping,
            initialSpringVelocity: velocity,
            options: nil,
            animations: {
                
            if self.isFrom {
                self.transform = CGAffineTransformIdentity
                self.alpha = 1
            }
            else {
                let translate = CGAffineTransformMakeTranslation(self.x, self.y)
                let scale = CGAffineTransformMakeScale(self.scaleX, self.scaleY)
                let rotate = CGAffineTransformMakeRotation(self.rotate)
                let translateAndScale = CGAffineTransformConcat(translate, scale)
                self.transform = CGAffineTransformConcat(rotate, translateAndScale)
                
                self.alpha = self.opacity
            }
                
        }, { finished in
            
            completion()
            
        })
    }
    
    func reset() {
        x = 0
        y = 0
        scaleX = 1
        scaleY = 1
        rotate = 0
        opacity = 1
    }
}
{'fraction_non_alphanumeric': 0.0948996918432803, 'fraction_numerical': 0.02760832652034463, 'mean_word_length': 1.6834289571380359, 'pattern_counts': {'":': 35, '<': 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': '3777265', 'n_tokens_mistral': 4935, 'n_tokens_neox': 4581, 'n_words': 1017}