<commit_before>//
//  UIView+Animation.swift
//  SwiftCommon
//
//  Created by <NAME> on 6/29/14.
//  Copyright (c) 2014 <NAME>. All rights reserved.
//

import UIKit
import QuartzCore


typealias UIViewAnimationCompletion = (Bool) -> Void

// MARK: Visibility
extension UIView {
    
    func toggleHidden() {hidden = !hidden}
    func hide() {hidden = true}
    func unhide() {hidden = false}
    
    func isVisible() -> Bool {return self.hidden == false}
    func isInvisible() -> Bool {return !isVisible()}
    
    func invisiblyChange(change: () -> Void) {hide(); change(); unhide()}
}

// MARK: Animation
extension UIView {

    func animateConstraint(duration: NSTimeInterval, animation:(()->Void)? = nil) {
        if let anim = animation {anim()}
        UIView.animateWithDuration(duration, animations: {self.layoutIfNeeded()})
    }
    
    func fadeIn(duration: NSTimeInterval, completion: UIViewAnimationCompletion? = nil) {
        let origAlpha = alpha
        invisiblyChange({self.alpha = 0.0})
        UIView.animateWithDuration(duration, animations: {self.alpha = origAlpha}, completion: completion)
    }

    func fadeBackgroundToBlack(duration: NSTimeInterval, completion: UIViewAnimationCompletion? = nil) {
        fadeBackgroundToColor(duration, color: UIColor.blackColor(), completion: completion)
    }
    
    func fadeBackgroundToColor(duration: NSTimeInterval, color: UIColor, completion: UIViewAnimationCompletion? = nil) {
        UIView.animateWithDuration(duration, animations: {self.backgroundColor = color}, completion: completion)
    }
    
    func fadeInText(text: String, duration: NSTimeInterval = 0.5) -> UILabel {
        let r = _G.rect(frame.origin.x, frame.size.height / 2.0, frame.size.width, 50.0)
        let label = UILabel.Builder.start(r.size).text(text).label!
        label.frame = r
        label.textAlignment = NSTextAlignment.Center
        label.textColor = UIColor.whiteColor()
        label.alpha = 0.0
        addSubview(label)
        
        UIView.animateWithDuration(duration, animations: {label.alpha = 1.0})
        return label
    }
    
    func fadeInCenteredText(text: String, duration: NSTimeInterval = 0.5, font: UIFont? = nil) -> UILabel {
        let label = fadeInText(text, duration: duration)
        label.setTranslatesAutoresizingMaskIntoConstraints(false)
        if let labelFont = font {label.font = labelFont}
        addConstraints(_C.centered(label, toItem: self))
        return label
    }

    func takeSnapshot() -> UIImage {
        UIGraphicsBeginImageContextWithOptions(bounds.size, true, 0)
        drawViewHierarchyInRect(bounds, afterScreenUpdates:true)
        let image = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return image
    }
    
    func zoomOut() {zoomOutWithKey("UIView.zoomOut")}
    func zoomOutWithKey(key: String) {
        let zoomOutAnimation = CABasicAnimation.zoomOut(0.3, timingFunction: TimingFunction.EaseInEaseOut)
        layer.addAnimation(zoomOutAnimation, forKey: key)
    }
    
    func zoomIn() {zoomInWithKey("UIView.zoomIn")}
    func zoomInWithKey(key: String) {
        let zoomInAnimation = CABasicAnimation.zoomIn(0.3, timingFunction: TimingFunction.EaseInEaseOut)
        layer.addAnimation(zoomInAnimation, forKey: key)
    }
}
<commit_msg>Version 0.0.21<commit_after>//
//  UIView+Animation.swift
//  SwiftCommon
//
//  Created by <NAME> on 6/29/14.
//  Copyright (c) 2014 <NAME>. All rights reserved.
//

import UIKit
import QuartzCore


typealias UIViewAnimationCompletion = (Bool) -> Void

// MARK: Visibility
extension UIView {
    
    func toggleHidden() {hidden = !hidden}
    func hide() {hidden = true}
    func unhide() {hidden = false}
    
    func isVisible() -> Bool {return self.hidden == false}
    func isInvisible() -> Bool {return !isVisible()}
    
    func invisiblyChange(change: () -> Void) {hide(); change(); unhide()}
}

// MARK: Animation
extension UIView {

    func animateConstraint(duration: NSTimeInterval, animation:(()->Void)? = nil) {
        if let anim = animation {anim()}
        UIView.animateWithDuration(duration, animations: {self.layoutIfNeeded()})
    }
    
    func fadeIn(duration: NSTimeInterval, completion: UIViewAnimationCompletion? = nil) {
        let origAlpha = alpha
        invisiblyChange({self.alpha = 0.0})
        UIView.animateWithDuration(duration, animations: {self.alpha = origAlpha}, completion: completion)
    }

    func fadeBackgroundToBlack(duration: NSTimeInterval, completion: UIViewAnimationCompletion? = nil) {
        fadeBackgroundToColor(duration, color: UIColor.blackColor(), completion: completion)
    }
    
    func fadeBackgroundToColor(duration: NSTimeInterval, color: UIColor, completion: UIViewAnimationCompletion? = nil) {
        UIView.animateWithDuration(duration, animations: {self.backgroundColor = color}, completion: completion)
    }
    
    func fadeInText(text: String, duration: NSTimeInterval = 0.5) -> UILabel {
        let r = _G.rect(frame.origin.x, frame.size.height / 2.0, frame.size.width, 50.0)
        let label = UILabel.Builder.start(r.size).text(text).label!
        label.frame = r
        label.textAlignment = NSTextAlignment.Center
        label.textColor = UIColor.whiteColor()
        label.alpha = 0.0
        addSubview(label)
        
        UIView.animateWithDuration(duration, animations: {label.alpha = 1.0})
        return label
    }
    
    func fadeInCenteredText(text: String, duration: NSTimeInterval = 0.5, font: UIFont? = nil) -> UILabel {
        let label = fadeInText(text, duration: duration)
        label.setTranslatesAutoresizingMaskIntoConstraints(false)
        if let labelFont = font {label.font = labelFont}
        addConstraints(_C.centered(label, toItem: self))
        return label
    }

    func takeSnapshot() -> UIImage {
        UIGraphicsBeginImageContextWithOptions(bounds.size, true, 0)
        drawViewHierarchyInRect(bounds, afterScreenUpdates:true)
        let image = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return image
    }
    
    func zoomOut(duration: NSTimeInterval = 0.3) -> CABasicAnimation {
        return zoomOutWithKey("UIView.zoomOut", duration: duration, delegate: nil)
    }
    
    func zoomOutWithKey(key: String, duration: NSTimeInterval = 0.3, delegate: AnyObject?) -> CABasicAnimation {
        let zoomOutAnimation = CABasicAnimation.zoomOut(duration, timingFunction: TimingFunction.EaseInEaseOut)
        if let animDelegate: AnyObject = delegate {zoomOutAnimation.delegate = animDelegate}
        zoomOutAnimation.setID(key)
        layer.addAnimation(zoomOutAnimation, forKey: key)
        return zoomOutAnimation
    }
    
    func zoomIn(duration: NSTimeInterval = 0.3) -> CABasicAnimation {
        return zoomInWithKey("UIView.zoomIn", duration: duration, delegate: nil)
    }
    
    func zoomInWithKey(key: String, duration: NSTimeInterval = 0.3, delegate: AnyObject?) -> CABasicAnimation {
        let zoomInAnimation = CABasicAnimation.zoomIn(duration, timingFunction: TimingFunction.EaseInEaseOut)
        if let animDelegate: AnyObject = delegate {zoomInAnimation.delegate = animDelegate}
        zoomInAnimation.setID(key)
        layer.addAnimation(zoomInAnimation, forKey: key)
        return zoomInAnimation
    }
}

{'fraction_non_alphanumeric': 0.10679347826086956, 'fraction_numerical': 0.008967391304347826, 'mean_word_length': 3.2896270396270397, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 27, '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': '257083', 'n_tokens_mistral': 2236, 'n_tokens_neox': 2145, 'n_words': 481}