This commit is contained in:
Scott Pfeil 2021-12-17 15:53:20 -05:00
parent 5aaf93186a
commit 9aad8e897c

View File

@ -38,16 +38,15 @@ import UIKit
weak public var delegate: TabsDelegate?
//control var
public var heightConstraint: NSLayoutConstraint?
public var selectedIndex: Int = 0
public var paddingBeforeFirstTab: Bool = true
//constant
let TabCellId = "TabCell"
public let sectionPadding: CGFloat = 20.0
public let itemSpacing: CGFloat = 20.0
public let cellHeight: CGFloat = 28.0
public let selectionLineHeight: CGFloat = 4.0
public let selectionLineWidth: CGFloat = 32.0
public let minimumItemWidth: CGFloat = 32.0
public let selectionLineMovingTime: TimeInterval = 0.2
//-------------------------------------------------
@ -112,7 +111,7 @@ import UIKit
selectionLine.heightAnchor.constraint(equalToConstant: selectionLineHeight).isActive = true
selectionLineLeftConstraint = selectionLine.leftAnchor.constraint(equalTo: bottomContentView.leftAnchor)
selectionLineLeftConstraint?.isActive = true
selectionLineWidthConstraint = selectionLine.widthAnchor.constraint(equalToConstant: selectionLineWidth)
selectionLineWidthConstraint = selectionLine.widthAnchor.constraint(equalToConstant: minimumItemWidth)
selectionLineWidthConstraint?.isActive = true
NSLayoutConstraint.constraintPinSubview(toSuperview: bottomContentView)
@ -189,7 +188,7 @@ extension Tabs: UICollectionViewDelegateFlowLayout {
guard let labelModel = tabsModel?.tabs[indexPath.row].label else {
return .zero
}
return CGSize(width: max(selectionLineWidth, getLabelWidth(labelModel).width), height: cellHeight)
return CGSize(width: max(minimumItemWidth, getLabelWidth(labelModel).width), height: cellHeight)
}
//pre calculate the width of the collection cell
@ -204,7 +203,7 @@ extension Tabs: UICollectionViewDelegateFlowLayout {
public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
guard section == 0 else {
return UIEdgeInsets(top: 0, left: sectionPadding, bottom: 0, right: 0)
return UIEdgeInsets(top: 0, left: itemSpacing, bottom: 0, right: 0)
}
guard paddingBeforeFirstTab else {
return .zero
@ -217,7 +216,7 @@ extension Tabs: UICollectionViewDelegateFlowLayout {
guard self.collectionView(collectionView, numberOfItemsInSection: section) != 2 else {
return 0
}
return sectionPadding
return itemSpacing
}
public func collectionView(_ collectionView: UICollectionView, shouldSelectItemAt indexPath: IndexPath) -> Bool {
@ -294,7 +293,7 @@ extension Tabs {
}
}
/// Adjust the line based on the percentage of the transition.
/// Adjust the line based on the percentage
func progress(from index: Int, toIndex: Int, percentage: CGFloat) {
let fromIndexPath = IndexPath(row: index, section: 0)
let toIndexPath = IndexPath(row: toIndex, section: 0)