<commit_before>//
//  UIViewExtensions.swift
//  Swiftility
//
//  Created by <NAME> on 9/22/15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import UIKit

// MARK: - Convenience init
extension UIView
{
    public convenience init(backgroundColor: UIColor)
    {
        self.init()
        self.backgroundColor = backgroundColor
    }
}

// MARK: - Animations
extension UIView
{
    /// Set hidden with animation using alpha property
    public func setHidden(
        _ hidden: Bool,
        animated: Bool,
        duration: TimeInterval = 0.2,
        customAnimations: (() -> Void)? = nil,
        completion: ((Void) -> Void)? = nil)
    {
        guard hidden != self.isHidden else {
            return
        }
        
        guard animated else {
            self.isHidden = hidden
            self.alpha = hidden ? 0 : 1
            customAnimations?()
            completion?()
            return
        }
        
        self.alpha = hidden ? 1 : 0
        
        if !hidden {
            self.isHidden = false
        }
        
        UIView.animate(
            withDuration: duration,
            delay: 0,
            options: .beginFromCurrentState,
            animations: {
                self.alpha = hidden ? 0 : 1
                customAnimations?()
            },
            completion: { finished in
                guard finished else { return }
                
                if hidden {
                    self.isHidden = true
                }
                
                completion?()
            }
        )
    }
}

// MARK: - Screenshot
extension UIView
{
    public func screenshot() -> UIImage?
    {
        let rect = self.bounds
        
        UIGraphicsBeginImageContext(rect.size)<commit_msg>Fix: UIView set hidden completion<commit_after>//
//  UIViewExtensions.swift
//  Swiftility
//
//  Created by <NAME> on 9/22/15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import UIKit

// MARK: - Convenience init
extension UIView
{
    public convenience init(backgroundColor: UIColor)
    {
        self.init()
        self.backgroundColor = backgroundColor
    }
}

// MARK: - Animations
extension UIView
{
    /// Set hidden with animation using alpha property
    public func setHidden(
        _ hidden: Bool,
        animated: Bool,
        duration: TimeInterval = 0.2,
        customAnimations: (() -> Void)? = nil,
        completion: ((Bool) -> Void)? = nil)
    {
        guard hidden != self.isHidden else {
            return
        }
        
        guard animated else {
            self.isHidden = hidden
            self.alpha = hidden ? 0 : 1
            customAnimations?()
            completion?(true)
            return
        }
        
        self.alpha = hidden ? 1 : 0
        
        if !hidden {
            self.isHidden = false
        }
        
        UIView.animate(
            withDuration: duration,
            delay: 0,
            options: .beginFromCurrentState,
            animations: {
                self.alpha = hidden ? 0 : 1
                customAnimations?()
            },
            completion: { finished in
                if hidden {
                    self.isHidden = true
                }
                
                completion?(finished)
            }
        )
    }
}

// MARK: - Screenshot
extension UIView
{
    public func screenshot() -> UIImage?
    {
        let rect = self.bounds
        
        UIGraphicsBeginImageContext(rect.size)
{'fraction_non_alphanumeric': 0.09197707736389685, 'fraction_numerical': 0.010315186246418338, 'mean_word_length': 1.2906824146981628, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, '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': '1889859', 'n_tokens_mistral': 966, 'n_tokens_neox': 908, 'n_words': 237}