Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CollectionViewWaterfallLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ open class CollectionViewWaterfallLayout: UICollectionViewLayout {
invalidateIfNotEqual(NSValue(uiEdgeInsets: oldValue), newValue: NSValue(uiEdgeInsets: sectionInset))
}
}

// A dictionary that maps from the CollectionView's section [key] to the item-width of its elements [value]. (read-only)
private(set) open var itemWidthForSection:[Int : Float] = [:]

//MARK: Private Properties
fileprivate weak var delegate: CollectionViewWaterfallLayoutDelegate? {
get {
Expand Down Expand Up @@ -141,6 +143,7 @@ open class CollectionViewWaterfallLayout: UICollectionViewLayout {
var top:Float = 0
var attributes: UICollectionViewLayoutAttributes

itemWidthForSection.removeAll()
for section in 0..<numberOfSections! {
/*
* 1. Get section-specific metrics (minimumInteritemSpacing, sectionInset)
Expand All @@ -163,6 +166,7 @@ open class CollectionViewWaterfallLayout: UICollectionViewLayout {

let width = Float(collectionView!.frame.size.width - sectionInset.left - sectionInset.right)
let itemWidth = floorf((width - Float(columnCount - 1) * Float(minimumColumnSpacing)) / Float(columnCount))
self.itemWidthForSection[section] = itemWidth

/*
* 2. Section header
Expand Down