From 512885a166fad5b4cbbfb8bdbd243bfd297ecd94 Mon Sep 17 00:00:00 2001 From: Arnaud Dorgans Date: Wed, 24 Oct 2018 22:07:54 +0200 Subject: [PATCH] bump & add public isEnabled property --- InfiniteLayout.podspec | 2 +- InfiniteLayout/Classes/InfiniteLayout.swift | 22 +++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/InfiniteLayout.podspec b/InfiniteLayout.podspec index 08d83bb..1170c24 100644 --- a/InfiniteLayout.podspec +++ b/InfiniteLayout.podspec @@ -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. diff --git a/InfiniteLayout/Classes/InfiniteLayout.swift b/InfiniteLayout/Classes/InfiniteLayout.swift index 7c4ff14..0a53ba4 100644 --- a/InfiniteLayout/Classes/InfiniteLayout.swift +++ b/InfiniteLayout/Classes/InfiniteLayout.swift @@ -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 { @@ -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) >= @@ -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, @@ -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) @@ -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)) @@ -247,7 +253,7 @@ open class InfiniteLayout: UICollectionViewFlowLayout { } public func centerCollectionView(withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer) { - 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, @@ -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),