<commit_before>//
//  ScrollableContainerView.swift
//  Visuality
//
//  Created by <NAME> on 06.11.16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import UIKit

public class ScrollableContainerView: UIView {
    
    // MARK: Class variables & properties
    
    // MARK: Public class methods
    
    // MARK: Private class methods
    
    fileprivate class func defaultScrollDirection() -> ScrollableContainerViewScrollDirection {
        return .vertical
    }
    
    // MARK: Initializers
    
    public override init(frame: CGRect) {
        super.init(frame: frame)
        customInitialization()
    }
    
    public required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        customInitialization()
    }
    
    // MARK: Deinitializer
    
    deinit {
        // Remove references
        
        lastContentSize = nil
        _internalScrollView = nil
        _contentView = nil
        _scrollDirection = nil
    }
    
    // MARK: Outlets
    
    // MARK: Object variables & properties
    
    fileprivate var lastContentSize: CGSize!
    
    fileprivate var _internalScrollView: UIScrollView!
    
    fileprivate var internalScrollView: UIScrollView {
        get {
            return _internalScrollView
        }
    }
    
    fileprivate var _contentView: UIView?
    
    public var contentView: UIView? {
        get {
            return _contentView
        }
        set {
            // Update content view
            
            setContentView(contentView: newValue, forScrollDirection: scrollDirection)
        }
    }
    
    fileprivate var _scrollDirection: ScrollableContainerViewScrollDirection!
    
    public var scrollDirection: ScrollableContainerViewScrollDirection {
        get {
            return _scrollDirection
        }
        set {
            // Update private variable
            
            _scrollDirection = newValue
            
            
            // Update content view
            
            setContentView(contentView: _contentView, forScrollDirection: newValue)
        }
    }
    
    // MARK: Public object methods
    
    public override func layoutSubviews() {
        super.layoutSubviews()
        
        // Update internal scroll view
        
        internalScrollView.frame = bounds
        
        let contentSizeForInternalScrollView = obtain(contentSizeForContentView: contentView, andScrollDirection: scrollDirection)
        
        if contentSizeForInternalScrollView != lastContentSize {
            internalScrollView.contentSize = contentSizeForInternalScrollView
            lastContentSize = contentSizeForInternalScrollView
        }
    }
    
    public func setContentView<ContentViewType: UIView>(ofType contentViewType: ContentViewType.Type, fromNibWithClassNameLocatedInBundle bundle: Bundle?, withScrollDirection scrollDirection: ScrollableContainerViewScrollDirection, andConfigurationBlock configurationBlock: ((_ contentView: ContentViewType) -> Void)?) {
        // Create new content view
        
        let newContentView = ContentViewType.vt_view(fromNibWithClassNameLocatedInBundle: bundle)
        
        // Update scroll direction
        
        _scrollDirection = scrollDirection
        
        // Update current content view
        
        contentView = newContentView
        
        // Configure new content view if needed
        
        configurationBlock?(newContentView)
    }
    
    // MARK: Private object methods
    
    fileprivate func customInitialization() {
        // Initialize view
        
        backgroundColor = .clear
        
        // Initialize internal scroll view
        
        _internalScrollView = UIScrollView(frame: bounds)
        internalScrollView.backgroundColor = .clear
        
        let contentSizeForInternalScrollView: CGSize = .zero
        lastContentSize = contentSizeForInternalScrollView<commit_msg>Use new API within ScrollableContainerView class<commit_after>//
//  ScrollableContainerView.swift
//  Visuality
//
//  Created by <NAME> on 06.11.16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import UIKit

public class ScrollableContainerView: UIView {
    
    // MARK: Class variables & properties
    
    // MARK: Public class methods
    
    // MARK: Private class methods
    
    fileprivate class func defaultScrollDirection() -> ScrollableContainerViewScrollDirection {
        return .vertical
    }
    
    // MARK: Initializers
    
    public override init(frame: CGRect) {
        super.init(frame: frame)
        customInitialization()
    }
    
    public required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        customInitialization()
    }
    
    // MARK: Deinitializer
    
    deinit {
        // Remove references
        
        lastContentSize = nil
        _internalScrollView = nil
        _contentView = nil
        _scrollDirection = nil
    }
    
    // MARK: Outlets
    
    // MARK: Object variables & properties
    
    fileprivate var lastContentSize: CGSize!
    
    fileprivate var _internalScrollView: UIScrollView!
    
    fileprivate var internalScrollView: UIScrollView {
        get {
            return _internalScrollView
        }
    }
    
    fileprivate var _contentView: UIView?
    
    public var contentView: UIView? {
        get {
            return _contentView
        }
        set {
            // Update content view
            
            setContentView(contentView: newValue, forScrollDirection: scrollDirection)
        }
    }
    
    fileprivate var _scrollDirection: ScrollableContainerViewScrollDirection!
    
    public var scrollDirection: ScrollableContainerViewScrollDirection {
        get {
            return _scrollDirection
        }
        set {
            // Update private variable
            
            _scrollDirection = newValue
            
            
            // Update content view
            
            setContentView(contentView: _contentView, forScrollDirection: newValue)
        }
    }
    
    // MARK: Public object methods
    
    public override func layoutSubviews() {
        super.layoutSubviews()
        
        // Update internal scroll view
        
        internalScrollView.frame = bounds
        
        let contentSizeForInternalScrollView = obtain(contentSizeForContentView: contentView, andScrollDirection: scrollDirection)
        
        if contentSizeForInternalScrollView != lastContentSize {
            internalScrollView.contentSize = contentSizeForInternalScrollView
            lastContentSize = contentSizeForInternalScrollView
        }
    }
    
    public func setContentView<ContentViewType: UIView>(ofType contentViewType: ContentViewType.Type, fromNibWithClassNameLocatedInBundle bundle: Bundle?, withScrollDirection scrollDirection: ScrollableContainerViewScrollDirection, andConfigurationBlock configurationBlock: ((_ contentView: ContentViewType) -> Void)?) {
        // Create new content view
        
        let newContentView = ContentViewType.from(nib: .byClassName, inBundle: .byValue(bundle: bundle ?? .main))
        
        // Update scroll direction
        
        _scrollDirection = scrollDirection
        
        // Update current content view
        
        contentView = newContentView
        
        // Configure new content view if needed
        
        configurationBlock?(newContentView)
    }
    
    // MARK: Private object methods
    
    fileprivate func customInitialization() {
        // Initialize view
        
        backgroundColor = .clear
        
        // Initialize internal scroll view
        
        _internalScrollView = UIScrollView(frame: bounds)
        internalScrollView.backgroundColor = .clear
        
        let contentSizeForInternalScrollView: CGSize = .zero
        lastContentSize = contentSizeForInternalScrollView
{'fraction_non_alphanumeric': 0.05886067955033472, 'fraction_numerical': 0.002526209422761147, 'mean_word_length': 2.022137404580153, 'pattern_counts': {'":': 0, '<': 9, '<?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': '4232940', 'n_tokens_mistral': 1961, 'n_tokens_neox': 1905, 'n_words': 470}