<commit_before>//
//  AutolayoutSize.swift
//  PulsarKit
//
//  Created by <NAME> on 02/03/2018.
//  Copyright © 2019 Nacoon. All rights reserved.
//

import UIKit

public struct AutolayoutSize: Sizeable {    
    public func size<View: UIView>(for view: View, descriptor: Descriptor, model: AnyHashable, in container: UIScrollView) -> CGSize {
        // starting bounds
        var bounds = container.bounds
        bounds = bounds.inset(by: container.contentInset)
        bounds = bounds.inset(by: container.sectionInset)
        
        // frame
        view.frame = bounds
        view.bounds = bounds
        
        // bind model
        descriptor.bind(cell: view, with: model)
        
        // layout
        view.setNeedsUpdateConstraints()
        view.layoutIfNeeded()
        
        // run autolayout
        let viewSize = view.systemLayoutSizeFitting(bounds.size,
                                                    withHorizontalFittingPriority: .defaultHigh,
                                                    verticalFittingPriority: .fittingSizeLevel)
        
        // cache
        return viewSize
    }
}<commit_msg>Added vertical and horizontal priority params in AutolayoutSize to better control size calculation.<commit_after>//
//  AutolayoutSize.swift
//  PulsarKit
//
//  Created by <NAME> on 02/03/2018.
//  Copyright © 2019 Nacoon. All rights reserved.
//

import UIKit

public struct AutolayoutSize: Sizeable {
    public let verticalFittingPriority: UILayoutPriority
    public let horizontalFittingPriority: UILayoutPriority
    
    public init(horizontalFittingPriority: UILayoutPriority = .defaultHigh, verticalFittingPriority: UILayoutPriority = .fittingSizeLevel) {
        self.verticalFittingPriority = verticalFittingPriority
        self.horizontalFittingPriority = horizontalFittingPriority
    }
    
    public func size<View: UIView>(for view: View, descriptor: Descriptor, model: AnyHashable, in container: UIScrollView) -> CGSize {
        // starting bounds
        var bounds = container.bounds
        bounds = bounds.inset(by: container.contentInset)
        bounds = bounds.inset(by: container.sectionInset)
        
        // frame
        view.frame = bounds
        view.bounds = bounds
        
        // bind model
        descriptor.bind(cell: view, with: model)
        
        // layout
        view.setNeedsUpdateConstraints()
        view.layoutIfNeeded()
        
        // run autolayout
        let viewSize = view.systemLayoutSizeFitting(bounds.size,
                                                    withHorizontalFittingPriority: horizontalFittingPriority,
                                                    verticalFittingPriority: verticalFittingPriority)
        
        // cache
        return viewSize
    }
}
{'fraction_non_alphanumeric': 0.07566024268379729, 'fraction_numerical': 0.008565310492505354, 'mean_word_length': 1.9474237644584649, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6609818', 'n_tokens_mistral': 724, 'n_tokens_neox': 692, 'n_words': 175}