<commit_before>//
//  TMTabItemBarButton.swift
//  Tabman
//
//  Created by <NAME> on 02/08/2018.
//  Copyright © 2019 UI At Six. All rights reserved.
//

import UIKit

/// `TMBarButton` which mimics appearance of a `UITabBarItem`, containing a image and label vertically aligned.
open class TMTabItemBarButton: TMBarButton {
    
    // MARK: Defaults
    
    private struct Defaults {
        static let imagePadding: CGFloat = 8.0
        static let imageSize = CGSize(width: 30.0, height: 30.0)
        static let labelPadding: CGFloat = 4.0
        static let labelTopPadding: CGFloat = 6.0
        static let shrunkenImageScale: CGFloat = 0.9
        static let badgeInsets = UIEdgeInsets(top: 4.0, left: 4.0, bottom: 0.0, right: 4.0)
    }
    
    // MARK: Properties
    
    private let container = UIView()
    private let label = AnimateableLabel()
    private let imageView = UIImageView()
    
    private var imageWidth: NSLayoutConstraint!
    private var imageHeight: NSLayoutConstraint!
    
    private var componentConstraints: [NSLayoutConstraint]?
    
    // MARK: Customization
    
    /// Tint color of the button when unselected / normal.
    open override var tintColor: UIColor! {
        didSet {
            if !isSelected {
                imageView.tintColor = tintColor
                label.textColor = tintColor
            }
        }
    }
    /// Tint color of the button when selected.
    open var selectedTintColor: UIColor! {
        didSet {
            if isSelected {
                imageView.tintColor = selectedTintColor
                label.textColor = selectedTintColor
            }
        }
    }
    /// Size of the image view.
    open var imageViewSize: CGSize {
        set {
            imageWidth.constant = newValue.width
            imageHeight.constant = newValue.height
        } get {
            return CGSize(width: imageWidth.constant, height: imageHeight.constant)
        }
    }
    /// Font of the text label.
    open var font: UIFont! {
        didSet {
            label.font = font
        }
    }
    /// Content Mode for the image view.
    open var imageContentMode: UIView.ContentMode {
        set {
            imageView.contentMode = newValue
        } get {
            return imageView.contentMode
        }
    }
    /// Whether to shrink the image view when unselected.
    ///
    /// Defaults to true.
    open var shrinksImageWhenUnselected: Bool = true {
        didSet {
            guard shrinksImageWhenUnselected else {
                return
            }
            if !self.isSelected {
                imageView.transform = CGAffineTransform(scaleX: Defaults.shrunkenImageScale, y: Defaults.shrunkenImageScale)
            }
        }
    }
    
    // MARK: Lifecycle
    
    open override func layout(in view: UIView) {
        super.layout(in: view)
        
        view.addSubview(container)
        container.addSubview(imageView)
        container.addSubview(label)
        
        container.translatesAutoresizingMaskIntoConstraints = false
        imageView.translatesAutoresizingMaskIntoConstraints = false
        label.translatesAutoresizingMaskIntoConstraints = false
        
        label.setContentHuggingPriority(.defaultLow, for: .horizontal)
        <commit_msg>Fix constraints for TMTabItemBarButton (#458)<commit_after>//
//  TMTabItemBarButton.swift
//  Tabman
//
//  Created by <NAME> on 02/08/2018.
//  Copyright © 2019 UI At Six. All rights reserved.
//

import UIKit

/// `TMBarButton` which mimics appearance of a `UITabBarItem`, containing a image and label vertically aligned.
open class TMTabItemBarButton: TMBarButton {
    
    // MARK: Defaults
    
    private struct Defaults {
        static let imagePadding: CGFloat = 8.0
        static let imageSize = CGSize(width: 30.0, height: 30.0)
        static let labelPadding: CGFloat = 4.0
        static let labelTopPadding: CGFloat = 6.0
        static let shrunkenImageScale: CGFloat = 0.9
        static let badgeInsets = UIEdgeInsets(top: 4.0, left: 4.0, bottom: 0.0, right: 4.0)
    }
    
    // MARK: Properties
    
    private let container = UIView()
    private let label = AnimateableLabel()
    private let imageView = UIImageView()
    
    private var imageWidth: NSLayoutConstraint!
    private var imageHeight: NSLayoutConstraint!
    
    private var componentConstraints: [NSLayoutConstraint]?
    
    // MARK: Customization
    
    /// Tint color of the button when unselected / normal.
    open override var tintColor: UIColor! {
        didSet {
            if !isSelected {
                imageView.tintColor = tintColor
                label.textColor = tintColor
            }
        }
    }
    /// Tint color of the button when selected.
    open var selectedTintColor: UIColor! {
        didSet {
            if isSelected {
                imageView.tintColor = selectedTintColor
                label.textColor = selectedTintColor
            }
        }
    }
    /// Size of the image view.
    open var imageViewSize: CGSize {
        set {
            imageWidth.constant = newValue.width
            imageHeight.constant = newValue.height
        } get {
            return CGSize(width: imageWidth.constant, height: imageHeight.constant)
        }
    }
    /// Font of the text label.
    open var font: UIFont! {
        didSet {
            label.font = font
        }
    }
    /// Content Mode for the image view.
    open var imageContentMode: UIView.ContentMode {
        set {
            imageView.contentMode = newValue
        } get {
            return imageView.contentMode
        }
    }
    /// Whether to shrink the image view when unselected.
    ///
    /// Defaults to true.
    open var shrinksImageWhenUnselected: Bool = true {
        didSet {
            guard shrinksImageWhenUnselected else {
                return
            }
            if !self.isSelected {
                imageView.transform = CGAffineTransform(scaleX: Defaults.shrunkenImageScale, y: Defaults.shrunkenImageScale)
            }
        }
    }
    
    // MARK: Lifecycle

    public required init(for item: TMBarItemable, intrinsicSuperview: UIView?) {
        super.init(for: item, intrinsicSuperview: intrinsicSuperview)

        if #available(iOS 13.0, *) {
            makeComponentConstraints(for: UIDevice.current.orientation)
        }
    }

    public required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    open override func layout(in view: UIView) {
        super.layout(in: view)
        
        view.addSubview(container)
        container.addSubview(imageView)
        container.addSubview(label)
        
        container.translatesAutoresizingMaskIntoConstraints = false
        imageView.translatesAutoresizingMaskIntoConstraints = false
        label.translatesAutoresizingMaskIntoConstraints = false
        
        label.setContentHuggingPriority(.defaultLow, for: .horizontal)
        
{'fraction_non_alphanumeric': 0.07712155963302753, 'fraction_numerical': 0.010607798165137615, 'mean_word_length': 1.9302813943721127, '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': '414800', 'n_tokens_mistral': 2023, 'n_tokens_neox': 1916, 'n_words': 515}