updated to use new selfsizing collectionview
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
5684104913
commit
e961315042
@ -41,15 +41,13 @@ public class RadioSwatchGroupBase<HandlerType: RadioSwatchBase>: SelectorGroupSe
|
||||
private let labelHeight: CGFloat = 16.0
|
||||
private let lineSpacing: CGFloat = 12.0
|
||||
private let itemSpacing: CGFloat = 16.0
|
||||
private var collectionViewHeight: NSLayoutConstraint?
|
||||
private var collectionViewWidth: NSLayoutConstraint?
|
||||
|
||||
fileprivate lazy var collectionView: UICollectionView = {
|
||||
fileprivate lazy var collectionView: SelfSizingCollectionView = {
|
||||
let layout = UICollectionViewFlowLayout().with {
|
||||
$0.minimumLineSpacing = lineSpacing
|
||||
$0.minimumInteritemSpacing = itemSpacing
|
||||
}
|
||||
return UICollectionView(frame: .zero, collectionViewLayout: layout).with {
|
||||
return SelfSizingCollectionView(frame: .zero, collectionViewLayout: layout).with {
|
||||
$0.backgroundColor = .clear
|
||||
$0.showsHorizontalScrollIndicator = false
|
||||
$0.showsVerticalScrollIndicator = false
|
||||
@ -100,37 +98,16 @@ public class RadioSwatchGroupBase<HandlerType: RadioSwatchBase>: SelectorGroupSe
|
||||
.pinTrailing()
|
||||
.pinBottom()
|
||||
|
||||
//TODO: Look at this width stuff, we should NOT need it!
|
||||
collectionViewWidth = collectionView.widthAnchor.constraint(equalToConstant: cellSize * 20)
|
||||
collectionViewWidth?.isActive = true
|
||||
|
||||
collectionViewHeight = collectionView.heightAnchor.constraint(equalToConstant: cellSize)
|
||||
collectionViewHeight?.isActive = true
|
||||
}
|
||||
|
||||
open override func layoutSubviews() {
|
||||
super.layoutSubviews()
|
||||
// Accounts for any collection size changes
|
||||
setHeight()
|
||||
DispatchQueue.main.async {
|
||||
self.collectionView.collectionViewLayout.invalidateLayout()
|
||||
}
|
||||
}
|
||||
|
||||
open func setHeight() {
|
||||
guard selectorViews.count > 0 else {
|
||||
collectionViewHeight?.constant = 0
|
||||
return
|
||||
}
|
||||
|
||||
// Calculate the height
|
||||
let swatchesInRow = floor(CGFloat(collectionView.bounds.width/(cellSize + itemSpacing)))
|
||||
let numberOfRows = ceil(CGFloat(selectorViews.count)/swatchesInRow)
|
||||
let height = (numberOfRows * cellSize) + (itemSpacing * (numberOfRows-1))
|
||||
|
||||
collectionViewHeight?.constant = CGFloat(height)
|
||||
}
|
||||
|
||||
public override func initialSetup() {
|
||||
super.initialSetup()
|
||||
collectionView.delegate = self
|
||||
|
||||
Loading…
Reference in New Issue
Block a user