<commit_before>//
//  Created by <NAME> on 06/05/16.
//  Copyright © 2018 TheLeftBit SL. All rights reserved.
//
#if canImport(UIKit)

import UIKit

@objc(BSWScrollableStackView)
open class ScrollableStackView: UIScrollView {

    private let stackView = UIStackView()

    public init(axis: NSLayoutConstraint.Axis = .vertical,
                alignment: UIStackView.Alignment = .leading) {
        super.init(frame: CGRect.zero)
        translatesAutoresizingMaskIntoConstraints = false
        stackView.axis = axis
        self.alignment = alignment

        addSubview(stackView)
        stackView.pinToSuperview()

        switch axis {
        case .horizontal:
            stackView.heightAnchor.constraint(equalTo: heightAnchor).isActive = true
            alwaysBounceHorizontal = true
        case .vertical:
            stackView.widthAnchor.constraint(equalTo: widthAnchor).isActive = true
            alwaysBounceVertical = true
        @unknown default:
            fatalError()
        }

        clipsToBounds = true
    }

    open func addArrangedSubview(_ subview: UIView, layoutMargins: UIEdgeInsets) {
        stackView.addArrangedSubview(subview, layoutMargins: layoutMargins)
    }

    open func addArrangedSubview(_ subview: UIView) {
        stackView.addArrangedSubview(subview)
    }

    required public init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    open override class var requiresConstraintBasedLayout : Bool {
        return true
    }

    open func viewAtIndex(_ index: Int) -> UIView? {
        return stackView.arrangedSubviews[safe: index]
    }

    open func indexOfView(_ view: UIView) -> Int? {
        return stackView.arrangedSubviews.firstIndex(of: view)
    }

    open func removeAllArrangedViews() {
        stackView.removeAllArrangedSubviews()
    }

    override open var layoutMargins: UIEdgeInsets {
        get {
            return stackView.layoutMargins
        }
        set {
            stackView.layoutMargins = newValue
            stackView.isLayoutMarginsRelativeArrangement = true
        }
    }

    open var spacing: CGFloat {
        get {
            return stackView.spacing
        } set {
            stackView.spacing = newValue
        }
    }
    
    open var alignment: UIStackView.Alignment {
        get {
            return stackView.alignment
        } set {
            stackView.alignment = newValue
        }
    }

    open var distribution: UIStackView.Distribution {
        get {
            return stackView.distribution
        } set {
            stackView.distribution = newValue
        }
    }
    
    open override func systemLayoutSizeFitting(_ targetSize: CGSize, withHorizontalFittingPriority horizontalFittingPriority: UILayoutPriority, verticalFittingPriority: UILayoutPriority) -> CGSize {
        return stackView.systemLayoutSizeFitting(targetSize, withHorizontalFittingPriority: horizontalFittingPriority, verticalFittingPriority: verticalFittingPriority)<commit_msg>Add more public methods to scrollableStackView (#246)<commit_after>//
//  Created by <NAME> on 06/05/16.
//  Copyright © 2018 TheLeftBit SL. All rights reserved.
//
#if canImport(UIKit)

import UIKit

@objc(BSWScrollableStackView)
open class ScrollableStackView: UIScrollView {

    private let stackView = UIStackView()

    public init(axis: NSLayoutConstraint.Axis = .vertical,
                alignment: UIStackView.Alignment = .leading) {
        super.init(frame: CGRect.zero)
        translatesAutoresizingMaskIntoConstraints = false
        stackView.axis = axis
        self.alignment = alignment

        addSubview(stackView)
        stackView.pinToSuperview()

        switch axis {
        case .horizontal:
            stackView.heightAnchor.constraint(equalTo: heightAnchor).isActive = true
            alwaysBounceHorizontal = true
        case .vertical:
            stackView.widthAnchor.constraint(equalTo: widthAnchor).isActive = true
            alwaysBounceVertical = true
        @unknown default:
            fatalError()
        }

        clipsToBounds = true
    }

    open func addArrangedSubview(_ subview: UIView, layoutMargins: UIEdgeInsets) {
        stackView.addArrangedSubview(subview, layoutMargins: layoutMargins)
    }

    open func addArrangedSubview(_ subview: UIView) {
        stackView.addArrangedSubview(subview)
    }

    open func insertArrangedSubview(_ view: UIView, at index: Int) {
        stackView.insertArrangedSubview(view, at: index)
    }
    
    required public init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    open override class var requiresConstraintBasedLayout : Bool {
        return true
    }

    open func viewAtIndex(_ index: Int) -> UIView? {
        return stackView.arrangedSubviews[safe: index]
    }

    open func indexOfView(_ view: UIView) -> Int? {
        return stackView.arrangedSubviews.firstIndex(of: view)
    }

    open func removeAllArrangedViews() {
        stackView.removeAllArrangedSubviews()
    }

    override open var layoutMargins: UIEdgeInsets {
        get {
            return stackView.layoutMargins
        }
        set {
            stackView.layoutMargins = newValue
            stackView.isLayoutMarginsRelativeArrangement = true
        }
    }

    open var spacing: CGFloat {
        get {
            return stackView.spacing
        } set {
            stackView.spacing = newValue
        }
    }
    
    open var alignment: UIStackView.Alignment {
        get {
            return stackView.alignment
        } set {
            stackView.alignment = newValue
        }
    }

    open var distribution: UIStackView.Distribution {
        get {
            return stackView.distribution
        } set {
            stackView.distribution = newValue
        }
    }
    
    open var arrangedSubviews: [UIView] {
        stackView.arrangedSubviews
    }
    
    open override func systemLayoutSizeFitting(_ targetSize: CGSize, withHorizontalFittingPriority horizontalFittingPriority: UILayoutPriority, verticalFittingPriority: UILayoutPriority) -> CGSize {
        return stackView.systemLayoutSizeFitting(targetSize, withHorizontalFittingPriority: horizontalFittingPriority, verticalFittingPriority: verticalFittingPriority)
{'fraction_non_alphanumeric': 0.07098814229249012, 'fraction_numerical': 0.0036363636363636364, 'mean_word_length': 2.4549426542872745, 'pattern_counts': {'":': 0, '<': 5, '<?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': '5107315', 'n_tokens_mistral': 1771, 'n_tokens_neox': 1673, 'n_words': 385}