Skip to content

Commit

Permalink
fix isEnabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud Dorgans committed Oct 24, 2018
1 parent 512885a commit c3688a9
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 10 deletions.
1 change: 1 addition & 0 deletions Example/InfiniteLayout/CustomViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import InfiniteLayout
class CustomViewController: UIViewController {

@IBOutlet weak var infiniteCollectionView: InfiniteCollectionView!

}

extension CustomViewController: UICollectionViewDataSource {
Expand Down
10 changes: 5 additions & 5 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
PODS:
- CocoaProxy (0.1.1)
- Differentiator (3.0.2)
- InfiniteLayout (0.2.3.1):
- InfiniteLayout (0.2.3.4):
- CocoaProxy (~> 0)
- InfiniteLayout/Core (= 0.2.3.1)
- InfiniteLayout/Core (0.2.3.1):
- InfiniteLayout/Core (= 0.2.3.4)
- InfiniteLayout/Core (0.2.3.4):
- CocoaProxy (~> 0)
- InfiniteLayout/Rx (0.2.3.1):
- InfiniteLayout/Rx (0.2.3.4):
- CocoaProxy (~> 0)
- InfiniteLayout/Core (~> 0)
- RxCocoa (~> 4)
Expand Down Expand Up @@ -39,7 +39,7 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
CocoaProxy: 35ab81e24325b33834cffe45a3d1fd48ca67ef3a
Differentiator: a87be69eba49ec4ab460c7671143ee3a9eececfd
InfiniteLayout: 17bbab705aa4d941fa82a7e9b658c96d13ce91a3
InfiniteLayout: 01f4d7bda9e2c5be476f10c670a02460e8568964
RxCocoa: cc1fec49cdc8fabe645964de7c51c099a36c2aa8
RxDataSources: cb7c31e652a87ebb919da45f716bbb87b3765f6b
RxSwift: 4219941c1244c88002901bd87a69d3aea9ae71f0
Expand Down
2 changes: 1 addition & 1 deletion InfiniteLayout/Classes/InfiniteCollectionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ extension InfiniteCollectionView: UICollectionViewDataSource {
}

private var multiplier: Int {
return InfiniteDataSources.multiplier(estimatedItemSize: self.infiniteLayout.itemSize)
return InfiniteDataSources.multiplier(estimatedItemSize: self.infiniteLayout.itemSize, enabled: self.infiniteLayout.isEnabled)
}

public func section(from infiniteSection: Int) -> Int {
Expand Down
5 changes: 4 additions & 1 deletion InfiniteLayout/Classes/InfiniteDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ class InfiniteDataSources {
return IndexPath(item: infiniteIndexPath.item % numberOfItems, section: self.section(from: infiniteIndexPath.section, numberOfSections: numberOfSections))
}

static func multiplier(estimatedItemSize: CGSize) -> Int {
static func multiplier(estimatedItemSize: CGSize, enabled: Bool) -> Int {
guard enabled else {
return 1
}
let min = Swift.min(estimatedItemSize.width, estimatedItemSize.height)
let count = ceil(InfiniteLayout.minimumContentSize / min)
return Int(count)
Expand Down
2 changes: 1 addition & 1 deletion InfiniteLayout/Classes/InfiniteLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ open class InfiniteLayout: UICollectionViewFlowLayout {

override open var collectionViewContentSize: CGSize {
guard hasValidLayout else {
return super.collectionViewContentSize
return self.contentSize
}
return CGSize(width: scrollDirection == .horizontal ? self.contentSize.width * multiplier : self.contentSize.width,
height: scrollDirection == .vertical ? self.contentSize.height * multiplier : self.contentSize.height)
Expand Down
8 changes: 6 additions & 2 deletions InfiniteLayout/Rx/RxInfiniteCollectionViewDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import UIKit
import RxDataSources

open class RxInfiniteCollectionViewSectionedReloadDataSource<S: SectionModelType>: RxCollectionViewSectionedReloadDataSource<S> {

public var isEnabled: Bool = true

open override subscript(section: Int) -> S {
let section = InfiniteDataSources.section(from: section, numberOfSections: sectionModels.count)
Expand All @@ -33,7 +35,7 @@ open class RxInfiniteCollectionViewSectionedReloadDataSource<S: SectionModelType
guard let layout = collectionView.collectionViewLayout as? UICollectionViewFlowLayout else {
fatalError()
}
return InfiniteDataSources.multiplier(estimatedItemSize: layout.itemSize)
return InfiniteDataSources.multiplier(estimatedItemSize: layout.itemSize, enabled: isEnabled)
}

open override func numberOfSections(in collectionView: UICollectionView) -> Int {
Expand All @@ -54,6 +56,8 @@ open class RxInfiniteCollectionViewSectionedReloadDataSource<S: SectionModelType

open class RxInfiniteCollectionViewSectionedAnimatedDataSource<S: AnimatableSectionModelType>: RxCollectionViewSectionedAnimatedDataSource<S> {

public var isEnabled: Bool = true

open override subscript(section: Int) -> S {
let section = InfiniteDataSources.section(from: section, numberOfSections: sectionModels.count)
return self.sectionModels[section]
Expand All @@ -77,7 +81,7 @@ open class RxInfiniteCollectionViewSectionedAnimatedDataSource<S: AnimatableSect
guard let layout = collectionView.collectionViewLayout as? UICollectionViewFlowLayout else {
fatalError()
}
return InfiniteDataSources.multiplier(estimatedItemSize: layout.itemSize)
return InfiniteDataSources.multiplier(estimatedItemSize: layout.itemSize, enabled: isEnabled)
}

open override func numberOfSections(in collectionView: UICollectionView) -> Int {
Expand Down

0 comments on commit c3688a9

Please sign in to comment.