Skip to content

Commit

Permalink
Move section index to property
Browse files Browse the repository at this point in the history
Summary:
This pull request removes the `sectionForSectionController:` method from the `IGListCollectionContext` protocol so that the protocol is exclusively for presentation methods.

This should not add new functionality, but rather makes the index directly accessible on the section controllers themselves. This change makes sense because at no time will there be an update to the list that the list adapter is unaware of and so it will always be able to set and update any indexes for a section controller that has changed.

Issue fixed: #609

- [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 added an entry to the `CHANGELOG.md` for any breaking changes, enhancements, or bug fixes.
- [X] I have reviewed the [contributing guide](https://github.com/Instagram/IGListKit/blob/master/.github/CONTRIBUTING.md)
Closes #671

Reviewed By: jessesquires

Differential Revision: D4942159

Pulled By: amonshiz

fbshipit-source-id: d648cfdd381cbf1d9ee7ff549ae27d2972a84622
  • Loading branch information
amonshiz authored and facebook-github-bot committed May 1, 2017
1 parent f1ebfbd commit a4e5ad8
Show file tree
Hide file tree
Showing 19 changed files with 527 additions and 351 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ This release closes the [3.0.0 milestone](https://github.com/Instagram/IGListKit
- `IGListUpdatingDelegate` now requires method `-reloadItemInCollectionView:fromIndexPath:toIndexPath:` to handle reloading cells between index paths. [Ryan Nystrom](https://github.com/rnystrom) [(#657)](https://github.com/Instagram/IGListKit/pull/657)
- `-[IGListCollectionContext sectionForSectionController:]` has been removed and replaced with the `NSInteger sectionIndex` property on `IGListSectionController`. [Andrew Monshizadeh](https://github.com/amonshiz) [#671](http://github.com/Instagram/IGListKit/pull/671)
### Enhancements
- Added an initializer on `IGListAdapter` that does not take a `workingRangeSize` and defaults it to 0. [BasThomas](https://github.com/BasThomas) [(#414)](https://github.com/Instagram/IGListKit/issues/414)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,26 @@ final class DisplaySectionController: IGListSectionController, IGListDisplayDele

override func cellForItem(at index: Int) -> UICollectionViewCell {
let cell = collectionContext!.dequeueReusableCell(of: LabelCell.self, for: self, at: index) as! LabelCell
let section = collectionContext!.section(for: self)
cell.text = "Section \(section), cell \(index)"
cell.text = "Section \(self.sectionIndex), cell \(index)"
return cell
}

// MARK: IGListDisplayDelegate

func listAdapter(_ listAdapter: IGListAdapter, willDisplay sectionController: IGListSectionController) {
let section = collectionContext!.section(for: self)
print("Will display section \(section)")
print("Will display section \(self.sectionIndex)")
}

func listAdapter(_ listAdapter: IGListAdapter, willDisplay sectionController: IGListSectionController, cell: UICollectionViewCell, at index: Int) {
let section = collectionContext!.section(for: self)
print("Did will display cell \(index) in section \(section)")
print("Did will display cell \(index) in section \(self.sectionIndex)")
}

func listAdapter(_ listAdapter: IGListAdapter, didEndDisplaying sectionController: IGListSectionController) {
let section = collectionContext!.section(for: self)
print("Did end displaying section \(section)")
print("Did end displaying section \(self.sectionIndex)")
}

func listAdapter(_ listAdapter: IGListAdapter, didEndDisplaying sectionController: IGListSectionController, cell: UICollectionViewCell, at index: Int) {
let section = collectionContext!.section(for: self)
print("Did end displaying cell \(index) in section \(section)")
print("Did end displaying cell \(index) in section \(self.sectionIndex)")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ final class ListeningSectionController: IGListSectionController, IncrementListen
}

func configureCell(cell: LabelCell) {
let section = collectionContext!.section(for: self)
cell.text = "Section: \(section), value: \(value)"
cell.text = "Section: \(self.sectionIndex), value: \(value)"
}

// MARK: IGListSectionController Overrides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ final class WorkingRangeSectionController: IGListSectionController, IGListWorkin
let url = URL(string: urlString)
else { return }

let section = collectionContext?.section(for: self) ?? 0
print("Downloading image \(urlString) for section \(section)")
print("Downloading image \(urlString) for section \(self.sectionIndex)")

task = URLSession.shared.dataTask(with: url) { data, response, err in
guard let data = data, let image = UIImage(data: data) else {
Expand Down
316 changes: 166 additions & 150 deletions Examples/Examples-iOS/Pods/Pods.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

104 changes: 56 additions & 48 deletions Examples/Examples-macOS/Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a4e5ad8

Please sign in to comment.