cleanup
This commit is contained in:
parent
5aaf93186a
commit
9aad8e897c
@ -38,16 +38,15 @@ import UIKit
|
|||||||
weak public var delegate: TabsDelegate?
|
weak public var delegate: TabsDelegate?
|
||||||
|
|
||||||
//control var
|
//control var
|
||||||
public var heightConstraint: NSLayoutConstraint?
|
|
||||||
public var selectedIndex: Int = 0
|
public var selectedIndex: Int = 0
|
||||||
public var paddingBeforeFirstTab: Bool = true
|
public var paddingBeforeFirstTab: Bool = true
|
||||||
|
|
||||||
//constant
|
//constant
|
||||||
let TabCellId = "TabCell"
|
let TabCellId = "TabCell"
|
||||||
public let sectionPadding: CGFloat = 20.0
|
public let itemSpacing: CGFloat = 20.0
|
||||||
public let cellHeight: CGFloat = 28.0
|
public let cellHeight: CGFloat = 28.0
|
||||||
public let selectionLineHeight: CGFloat = 4.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
|
public let selectionLineMovingTime: TimeInterval = 0.2
|
||||||
|
|
||||||
//-------------------------------------------------
|
//-------------------------------------------------
|
||||||
@ -112,7 +111,7 @@ import UIKit
|
|||||||
selectionLine.heightAnchor.constraint(equalToConstant: selectionLineHeight).isActive = true
|
selectionLine.heightAnchor.constraint(equalToConstant: selectionLineHeight).isActive = true
|
||||||
selectionLineLeftConstraint = selectionLine.leftAnchor.constraint(equalTo: bottomContentView.leftAnchor)
|
selectionLineLeftConstraint = selectionLine.leftAnchor.constraint(equalTo: bottomContentView.leftAnchor)
|
||||||
selectionLineLeftConstraint?.isActive = true
|
selectionLineLeftConstraint?.isActive = true
|
||||||
selectionLineWidthConstraint = selectionLine.widthAnchor.constraint(equalToConstant: selectionLineWidth)
|
selectionLineWidthConstraint = selectionLine.widthAnchor.constraint(equalToConstant: minimumItemWidth)
|
||||||
selectionLineWidthConstraint?.isActive = true
|
selectionLineWidthConstraint?.isActive = true
|
||||||
NSLayoutConstraint.constraintPinSubview(toSuperview: bottomContentView)
|
NSLayoutConstraint.constraintPinSubview(toSuperview: bottomContentView)
|
||||||
|
|
||||||
@ -189,7 +188,7 @@ extension Tabs: UICollectionViewDelegateFlowLayout {
|
|||||||
guard let labelModel = tabsModel?.tabs[indexPath.row].label else {
|
guard let labelModel = tabsModel?.tabs[indexPath.row].label else {
|
||||||
return .zero
|
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
|
//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 {
|
public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
|
||||||
guard section == 0 else {
|
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 {
|
guard paddingBeforeFirstTab else {
|
||||||
return .zero
|
return .zero
|
||||||
@ -217,7 +216,7 @@ extension Tabs: UICollectionViewDelegateFlowLayout {
|
|||||||
guard self.collectionView(collectionView, numberOfItemsInSection: section) != 2 else {
|
guard self.collectionView(collectionView, numberOfItemsInSection: section) != 2 else {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
return sectionPadding
|
return itemSpacing
|
||||||
}
|
}
|
||||||
|
|
||||||
public func collectionView(_ collectionView: UICollectionView, shouldSelectItemAt indexPath: IndexPath) -> Bool {
|
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) {
|
func progress(from index: Int, toIndex: Int, percentage: CGFloat) {
|
||||||
let fromIndexPath = IndexPath(row: index, section: 0)
|
let fromIndexPath = IndexPath(row: index, section: 0)
|
||||||
let toIndexPath = IndexPath(row: toIndex, section: 0)
|
let toIndexPath = IndexPath(row: toIndex, section: 0)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user