Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions Source/SFFocusViewLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ public class SFFocusViewLayout: UICollectionViewLayout {
private extension UICollectionViewLayout {

var numberOfItems: Int {
guard collectionView?.numberOfSections() > 0 else {
return 0
}

return collectionView!.numberOfItemsInSection(0)
}

Expand Down
4 changes: 3 additions & 1 deletion Tests/CollectionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ private let reuseIdentifier = "Cell"
class CollectionViewController: UICollectionViewController {

var items = [Int]()

var numberOfSectionsToReturn = 1

override func viewDidLoad() {
super.viewDidLoad()
Expand All @@ -23,7 +25,7 @@ class CollectionViewController: UICollectionViewController {
// MARK: UICollectionViewDataSource

override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 1
return numberOfSectionsToReturn
}


Expand Down
5 changes: 5 additions & 0 deletions Tests/Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,10 @@ class Tests: XCTestCase {
func testLayoutShouldInvalidateLayoutForBoundsChange() {
XCTAssertTrue(focusViewLayout.shouldInvalidateLayoutForBoundsChange(CGRect()))
}

func testCanPrepareLayoutForCollectionViewWithZeroSections() {
collectionViewController?.numberOfSectionsToReturn = 0
focusViewLayout.prepareLayout()
}

}