Skip to content

Commit

Permalink
Fixed tail loading example (#105)
Browse files Browse the repository at this point in the history
Summary:
- Fixes #105
- ~~Added a 'SpinnerSectionController' allowing us to trigger the activity spinner each time~~
- Changed the words array to be numbers instead (I found it personally difficult to realise if more cells were actually added as the text didn't seem to change, by using numbers you can quite clearly see it increment by 5 each time you load more)
- No changes/new tests as it is a fix to an example

- [x] All tests pass. Demo project builds and runs.
- [x] I added tests, an experiment, or detailed why my change isn't tested.
- [x] I have reviewed the [contributing guide](https://github.com/Instagram/IGListKit/blob/master/CONTRIBUTING.md)
Closes #109

Differential Revision: D4066700

Pulled By: rnystrom

fbshipit-source-id: 7779a8ba39361cfa2e782db9460e693e90f1a478
  • Loading branch information
Sherlock authored and Facebook Github Bot committed Oct 24, 2016
1 parent d78c0b4 commit 8ccdc83
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class LabelSectionController: IGListSectionController, IGListSectionType {
}

func didUpdate(to object: Any) {
self.object = object as? String
self.object = String(describing: object)
}

func didSelectItem(at index: Int) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class LoadMoreViewController: UIViewController, IGListAdapterDataSource, UIScrol
}()
let collectionView = IGListCollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout())

lazy var words = "Maecenas faucibus mollis interdum Praesent commodo cursus magna, vel scelerisque nisl consectetur et".components(separatedBy: " ")
lazy var items = Array(0...20)
var loading = false
let spinToken = NSObject()

Expand All @@ -42,11 +42,13 @@ class LoadMoreViewController: UIViewController, IGListAdapterDataSource, UIScrol
//MARK: IGListAdapterDataSource

func objects(for listAdapter: IGListAdapter) -> [IGListDiffable] {
var items: [IGListDiffable] = words as [IGListDiffable]
var objects = items as [IGListDiffable]

if loading {
items.append(spinToken)
objects.append(spinToken)
}
return items

return objects
}

func listAdapter(_ listAdapter: IGListAdapter, sectionControllerFor object: Any) -> IGListSectionController {
Expand All @@ -71,7 +73,8 @@ class LoadMoreViewController: UIViewController, IGListAdapterDataSource, UIScrol
sleep(2)
DispatchQueue.main.async {
self.loading = false
self.words.append(contentsOf: "Etiam porta sem malesuada magna mollis euismod".components(separatedBy: " "))
let itemCount = self.items.count
self.items.append(contentsOf: Array(itemCount..<itemCount + 5))
self.adapter.performUpdates(animated: true, completion: nil)
}
})
Expand Down
10 changes: 7 additions & 3 deletions Example/IGListKitExamples/Views/SpinnerCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@ import UIKit
import IGListKit

func spinnerSectionController() -> IGListSingleSectionController {
let configureBlock = { (item: Any, cell: UICollectionViewCell) in}
let configureBlock = { (item: Any, cell: UICollectionViewCell) in
guard let cell = cell as? SpinnerCell else { return }
cell.activityIndicator.startAnimating()
}

let sizeBlock = { (context: IGListCollectionContext?) -> CGSize in
guard let context = context else { return CGSize() }
guard let context = context else { return .zero }
return CGSize(width: context.containerSize.width, height: 100)
}

return IGListSingleSectionController(cellClass: SpinnerCell.self,
configureBlock: configureBlock,
sizeBlock: sizeBlock)
Expand All @@ -30,7 +35,6 @@ class SpinnerCell: UICollectionViewCell {

lazy var activityIndicator: UIActivityIndicatorView = {
let view = UIActivityIndicatorView(activityIndicatorStyle: .gray)
view.startAnimating()
self.contentView.addSubview(view)
return view
}()
Expand Down

0 comments on commit 8ccdc83

Please sign in to comment.