Skip to content

Commit

Permalink
Add delegate method for minimumColumnSpacing
Browse files Browse the repository at this point in the history
  • Loading branch information
ApolloZhu committed Dec 10, 2021
1 parent 88b81c2 commit de37d0b
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions Source/CHTCollectionViewWaterfallLayout.swift
Expand Up @@ -53,6 +53,10 @@ private func > <T: Comparable>(lhs: T?, rhs: T?) -> Bool {
@objc optional func collectionView(_ collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
columnCountFor section: Int) -> Int

@objc optional func collectionView(_ collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
minimumColumnSpacingFor section: Int) -> CGFloat

@available(*, unavailable, renamed: "collectionView(_:layout:sizeForItemAt:)")
@objc optional func collectionView (_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout,
Expand Down Expand Up @@ -205,10 +209,13 @@ public class CHTCollectionViewWaterfallLayout: UICollectionViewLayout {
}

public func itemWidth(inSection section: Int) -> CGFloat {
let columnCount = self.columnCount(forSection: section)
let spaceColumCount = CGFloat(columnCount - 1)
let width = collectionViewContentWidth(ofSection: section)
return floor((width - (spaceColumCount * minimumColumnSpacing)) / CGFloat(columnCount))

let columnCount = self.columnCount(forSection: section)
let spaceColumnCount = CGFloat(columnCount - 1)
let columnSpacing = delegate?.collectionView?(collectionView!, layout: self, minimumColumnSpacingFor: section) ?? minimumColumnSpacing

return floor((width - (spaceColumnCount * columnSpacing)) / CGFloat(columnCount))
}

override public func prepare() {
Expand Down

0 comments on commit de37d0b

Please sign in to comment.