Skip to content

Commit

Permalink
bump & add public isEnabled property
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud Dorgans committed Oct 24, 2018
1 parent 8fad957 commit 512885a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion InfiniteLayout.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'InfiniteLayout'
s.version = '0.2.3.3'
s.version = '0.2.3.4'
s.summary = 'Horizontal and Vertical infinite scrolling feature for UICollectionView with Paging, NSProxy delegate, Reactive extension'

# This description is used to generate tags and improve search results.
Expand Down
22 changes: 14 additions & 8 deletions InfiniteLayout/Classes/InfiniteLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ open class InfiniteLayout: UICollectionViewFlowLayout {

private var contentSize: CGSize = .zero

private (set) var isEnabled: Bool = false
private var hasValidLayout: Bool = false

@IBInspectable public var isEnabled: Bool = true {
didSet {
self.invalidateLayout()
}
}

public var currentPage: CGPoint {
guard let collectionView = self.collectionView else {
Expand Down Expand Up @@ -49,8 +55,8 @@ open class InfiniteLayout: UICollectionViewFlowLayout {
override open func prepare() {
let collectionViewContentSize = super.collectionViewContentSize
self.contentSize = CGSize(width: collectionViewContentSize.width, height: collectionViewContentSize.height)
self.isEnabled = {
guard let collectionView = self.collectionView, collectionView.bounds != .zero else {
self.hasValidLayout = {
guard let collectionView = self.collectionView, collectionView.bounds != .zero, self.isEnabled else {
return false
}
return (scrollDirection == .horizontal ? self.contentSize.width : self.contentSize.height) >=
Expand All @@ -60,7 +66,7 @@ open class InfiniteLayout: UICollectionViewFlowLayout {
}

override open var collectionViewContentSize: CGSize {
guard isEnabled else {
guard hasValidLayout else {
return super.collectionViewContentSize
}
return CGSize(width: scrollDirection == .horizontal ? self.contentSize.width * multiplier : self.contentSize.width,
Expand All @@ -75,7 +81,7 @@ open class InfiniteLayout: UICollectionViewFlowLayout {
}

override open func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
guard isEnabled else {
guard hasValidLayout else {
return super.layoutAttributesForElements(in: rect)
}
let page = self.page(for: rect.origin)
Expand Down Expand Up @@ -157,7 +163,7 @@ open class InfiniteLayout: UICollectionViewFlowLayout {
}

public func loopCollectionViewIfNeeded() {
guard let collectionView = self.collectionView, self.isEnabled else {
guard let collectionView = self.collectionView, self.hasValidLayout else {
return
}
let page = self.pageIndex(from: self.page(for: collectionView.contentOffset))
Expand Down Expand Up @@ -247,7 +253,7 @@ open class InfiniteLayout: UICollectionViewFlowLayout {
}

public func centerCollectionView(withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
guard let collectionView = self.collectionView, self.isEnabled else {
guard let collectionView = self.collectionView, self.hasValidLayout else {
return
}
let newTarget = CGPoint(x: self.scrollDirection == .horizontal ? collectionView.contentOffset.x + velocity.x * velocityMultiplier : targetContentOffset.pointee.x,
Expand All @@ -261,7 +267,7 @@ open class InfiniteLayout: UICollectionViewFlowLayout {
}

public func centerCollectionViewIfNeeded(indexPath: IndexPath? = nil) {
guard let collectionView = self.collectionView, self.isEnabled else {
guard let collectionView = self.collectionView, self.hasValidLayout else {
return
}
guard let preferredAttributes = self.preferredVisibleLayoutAttributes(indexPath: indexPath),
Expand Down

0 comments on commit 512885a

Please sign in to comment.