<commit_before>//
//  UIScrollView+CSExtension.swift
//  Renetik
//
//  Created by <NAME> on 3/6/19.
//

import UIKit
import RenetikObjc

public extension UIScrollView {

    static let scrollStateInaccuracy: CGFloat = 15

    @discardableResult
    func contentOffset(top: CGFloat, animated: Bool = true) -> Self {
        invoke(animated: animated) {
            self.contentOffset = CGPoint(left: self.contentOffset.left, top: top)
        }
        return self
    }

    @discardableResult
    func contentOffset(left: CGFloat, animated: Bool = true) -> Self {
        invoke(animated: animated) {
            self.contentOffset = CGPoint(left: left, top: self.contentOffset.top)
        }
        return self
    }

    @discardableResult
    func content(inset: UIEdgeInsets) -> Self { self.contentInset = inset; return self }

//    class func vertical(content view: UIView) -> Self {
//        let instance: UIScrollView = Self.withSize(view.width, view.height)
//        instance.vertical(content: view)
//        return instance as! Self
//    }

//    class func horizontal(content view: UIView) -> Self {
//        let instance: UIScrollView = Self.withSize(view.width, view.height)
//        instance.horizontal(content: view)
//        return instance as! Self
//    }

    public func scrollable(_ isScrollEnabled: Bool) -> Self {
        self.isScrollEnabled = isScrollEnabled
        return self
    }

    public var isAtTop: Bool { contentOffset.y <= verticalOffsetForTop }

    public var isAtBottom: Bool {
//        let bottomEdge = contentOffset.y + height
//        return bottomEdge >= contentSize.height
        contentOffset.y >= verticalOffsetForBottom
    }

    public var verticalOffsetForTop: CGFloat {
        let topInset = contentInset.top
        return -topInset
    }

    public var verticalOffsetForBottom: CGFloat {
        let scrollViewHeight = bounds.height
        let scrollContentSizeHeight = contentSize.height
        let bottomInset = contentInset.bottom
        let scrollViewBottomOffset = scrollContentSizeHeight + bottomInset - scrollViewHeight
        return scrollViewBottomOffset.rounded()
    }

    @discardableResult
    func content<View: UIView>(horizontal view: View) -> View {
        content(view).matchParentHeight().from(left: 0)
        contentSizeWidthByLastContentSubview()
        return view
    }

    @discardableResult
    public func content<View: UIView>(vertical view: View) -> View {
        content(view).matchParentWidth().from(top: 0)
        contentSizeHeightByLastContentSubview()
        return view
    }

    @discardableResult
    func contentSize(width: CGFloat) -> Self {
        contentSize = CGSize(width: width, height: contentSize.height)
        return self
    }

    @discardableResult
    func contentSize(height: CGFloat) -> Self {
        contentSize = CGSize(width: contentSize.width, height: height)
        return self
    }

    @discardableResult
    func contentSizeWidthByLastContentSubview(padding: CGFloat = 0) -> Self {
        content!.width = (content!.subviews.last?.right ?? 0) + padding
        if content!.width < width { content!.width = width }
        contentSize(width: content!.right)
        return self
    }

    @discardableResult
    func contentSizeHeightByLastContentSubview(padding: CGFloat = 0) -> Self {
        content!.height = (content!.subviews.last?.bottom ?? 0) + padding
        if content!.height < height { content!.height = height }
        contentSize(height: content!.bottom)
        return self
    }

    func scrollToTop() {
        setContentOffset(CGPoint(x: contentOffset.x, y: -contentInset.top), animated: true)
    }

    func scrollToBottom() {
        setContentOffset(CGPoint(x: contentOffset.x,
                y: contentSize.height - bounds.size.height - contentInset.bottom), animated: true)
    }<commit_msg>no message<commit_after>//
//  UIScrollView+CSExtension.swift
//  Renetik
//
//  Created by <NAME> on 3/6/19.
//

import UIKit
import RenetikObjc

public extension UIScrollView {

    static let scrollStateInaccuracy: CGFloat = 15

    @discardableResult
    func contentOffset(top: CGFloat, animated: Bool = true) -> Self {
        invoke(animated: animated) {
            self.contentOffset = CGPoint(left: self.contentOffset.left, top: top)
        }
        return self
    }

    @discardableResult
    func contentOffset(left: CGFloat, animated: Bool = true) -> Self {
        invoke(animated: animated) {
            self.contentOffset = CGPoint(left: left, top: self.contentOffset.top)
        }
        return self
    }

    @discardableResult
    func content(inset: UIEdgeInsets) -> Self { self.contentInset = inset; return self }

//    class func vertical(content view: UIView) -> Self {
//        let instance: UIScrollView = Self.withSize(view.width, view.height)
//        instance.vertical(content: view)
//        return instance as! Self
//    }

//    class func horizontal(content view: UIView) -> Self {
//        let instance: UIScrollView = Self.withSize(view.width, view.height)
//        instance.horizontal(content: view)
//        return instance as! Self
//    }

    public func scrollable(_ isScrollEnabled: Bool) -> Self {
        self.isScrollEnabled = isScrollEnabled
        return self
    }

    public var isAtTop: Bool { contentOffset.y <= verticalOffsetForTop }

    public var isAtBottom: Bool {
//        let bottomEdge = contentOffset.y + height
//        return bottomEdge >= contentSize.height
        contentOffset.y >= verticalOffsetForBottom
    }

    public var verticalOffsetForTop: CGFloat {
        let topInset = contentInset.top
        return -topInset
    }

    public var verticalOffsetForBottom: CGFloat {
        let scrollViewHeight = bounds.height
        let scrollContentSizeHeight = contentSize.height
        let bottomInset = contentInset.bottom
        let scrollViewBottomOffset = scrollContentSizeHeight + bottomInset - scrollViewHeight
        return scrollViewBottomOffset.rounded()
    }

    @discardableResult
    func content<View: UIView>(horizontal view: View) -> View {
        content(view).matchParentHeight().from(left: 0)
        contentWidthByLastContentSubview()
        return view
    }

    @discardableResult
    public func content<View: UIView>(vertical view: View) -> View {
        content(view).matchParentWidth().from(top: 0)
        contentHeightByLastContentSubview()
        return view
    }

    @discardableResult
    func contentSize(width: CGFloat) -> Self {
        contentSize = CGSize(width: width, height: contentSize.height)
        return self
    }

    @discardableResult
    func contentSize(height: CGFloat) -> Self {
        contentSize = CGSize(width: contentSize.width, height: height)
        return self
    }

    @discardableResult
    func contentWidthByLastContentSubview(padding: CGFloat = 0) -> Self {
        content!.width = (content!.subviews.last?.right ?? 0) + padding
        if content!.width < width { content!.width = width }
        contentSize(width: content!.right)
        return self
    }

    @discardableResult
    func contentHeightByLastContentSubview(padding: CGFloat = 0) -> Self {
        content!.height = (content!.subviews.last?.bottom ?? 0) + padding
        if content!.height < height { content!.height = height }
        contentSize(height: content!.bottom)
        return self
    }

    func scrollToTop() {
        setContentOffset(CGPoint(x: contentOffset.x, y: -contentInset.top), animated: true)
    }

    func scrollToBottom() {
        setContentOffset(CGPoint(x: contentOffset.x,
                y: contentSize.height - bounds.size.height - contentInset.bottom), animated: true)
    }
{'fraction_non_alphanumeric': 0.09796553064662433, 'fraction_numerical': 0.0031100168459245823, 'mean_word_length': 2.640566037735849, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 37, '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': '7323422', 'n_tokens_mistral': 2262, 'n_tokens_neox': 2158, 'n_words': 521}