mirror of
https://github.com/Instagram/IGListKit
synced 2026-05-23 17:28:22 +00:00
Remove refs to IGListSectionType, fix TV app example
Summary: - Clean up docs - Remove `IGListSectionType` and `IGListCollectionView` - Fix TV app example Issue fixed: #675 - [x] All tests pass. Demo project builds and runs. Closes https://github.com/Instagram/IGListKit/pull/676 Differential Revision: D4915634 Pulled By: rnystrom fbshipit-source-id: 60eb1f1e5ece7fe68f6bf44b465bd5379615d716
This commit is contained in:
parent
145327647b
commit
ad416ecccd
6 changed files with 36 additions and 30 deletions
|
|
@ -15,7 +15,7 @@
|
|||
import UIKit
|
||||
import IGListKit
|
||||
|
||||
final class CarouselSectionController: IGListSectionController, IGListSectionType {
|
||||
final class CarouselSectionController: IGListSectionController {
|
||||
|
||||
var number: Int?
|
||||
|
||||
|
|
@ -24,11 +24,11 @@ final class CarouselSectionController: IGListSectionController, IGListSectionTyp
|
|||
self.inset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 10)
|
||||
}
|
||||
|
||||
func numberOfItems() -> Int {
|
||||
override func numberOfItems() -> Int {
|
||||
return 1
|
||||
}
|
||||
|
||||
func sizeForItem(at index: Int) -> CGSize {
|
||||
override func sizeForItem(at index: Int) -> CGSize {
|
||||
let height = collectionContext?.containerSize.height ?? 0
|
||||
let aspectRatio: CGFloat = 0.75 // 3:4
|
||||
let width = height * aspectRatio
|
||||
|
|
@ -36,17 +36,17 @@ final class CarouselSectionController: IGListSectionController, IGListSectionTyp
|
|||
return CGSize(width: width, height: height)
|
||||
}
|
||||
|
||||
func cellForItem(at index: Int) -> UICollectionViewCell {
|
||||
override func cellForItem(at index: Int) -> UICollectionViewCell {
|
||||
let cell = collectionContext!.dequeueReusableCell(withNibName: "CarouselCell", bundle: nil, for: self, at: index) as! CarouselCell
|
||||
let value = number ?? 0
|
||||
cell.titleLabel.text = "#\(value + 1)"
|
||||
return cell
|
||||
}
|
||||
|
||||
func didUpdate(to object: Any) {
|
||||
override func didUpdate(to object: Any) {
|
||||
number = object as? Int
|
||||
}
|
||||
|
||||
func didSelectItem(at index: Int) {}
|
||||
override func didSelectItem(at index: Int) {}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ final class DemoItem: NSObject {
|
|||
|
||||
}
|
||||
|
||||
final class DemoSectionController: IGListSectionController, IGListSectionType {
|
||||
final class DemoSectionController: IGListSectionController {
|
||||
|
||||
var object: DemoItem?
|
||||
|
||||
|
|
@ -40,26 +40,26 @@ final class DemoSectionController: IGListSectionController, IGListSectionType {
|
|||
inset = UIEdgeInsets(top: 0, left: 50, bottom: 10, right: 0)
|
||||
}
|
||||
|
||||
func numberOfItems() -> Int {
|
||||
override func numberOfItems() -> Int {
|
||||
return 1
|
||||
}
|
||||
|
||||
func sizeForItem(at index: Int) -> CGSize {
|
||||
override func sizeForItem(at index: Int) -> CGSize {
|
||||
let itemWidth = (collectionContext!.containerSize.width / 2) - inset.left
|
||||
return CGSize(width: itemWidth, height: 100)
|
||||
}
|
||||
|
||||
func cellForItem(at index: Int) -> UICollectionViewCell {
|
||||
override func cellForItem(at index: Int) -> UICollectionViewCell {
|
||||
let cell = collectionContext!.dequeueReusableCell(of: DemoCell.self, for: self, at: index) as! DemoCell
|
||||
cell.label.text = object?.name
|
||||
return cell
|
||||
}
|
||||
|
||||
func didUpdate(to object: Any) {
|
||||
override func didUpdate(to object: Any) {
|
||||
self.object = object as? DemoItem
|
||||
}
|
||||
|
||||
func didSelectItem(at index: Int) {
|
||||
override func didSelectItem(at index: Int) {
|
||||
if let identifier = object?.controllerIdentifier {
|
||||
let storyboard = UIStoryboard(name: "Demo", bundle: nil)
|
||||
let controller = storyboard.instantiateViewController(withIdentifier: identifier)
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
import UIKit
|
||||
import IGListKit
|
||||
|
||||
final class HorizontalSectionController: IGListSectionController, IGListSectionType, IGListAdapterDataSource {
|
||||
final class HorizontalSectionController: IGListSectionController, IGListAdapterDataSource {
|
||||
|
||||
var number: Int?
|
||||
|
||||
|
|
@ -32,25 +32,25 @@ final class HorizontalSectionController: IGListSectionController, IGListSectionT
|
|||
self.inset = UIEdgeInsets(top: 20, left: 0, bottom: 20, right: 0)
|
||||
}
|
||||
|
||||
func numberOfItems() -> Int {
|
||||
override func numberOfItems() -> Int {
|
||||
return 1
|
||||
}
|
||||
|
||||
func sizeForItem(at index: Int) -> CGSize {
|
||||
override func sizeForItem(at index: Int) -> CGSize {
|
||||
return CGSize(width: collectionContext!.containerSize.width, height: 340)
|
||||
}
|
||||
|
||||
func cellForItem(at index: Int) -> UICollectionViewCell {
|
||||
override func cellForItem(at index: Int) -> UICollectionViewCell {
|
||||
let cell = collectionContext!.dequeueReusableCell(of: EmbeddedCollectionViewCell.self, for: self, at: index) as! EmbeddedCollectionViewCell
|
||||
adapter.collectionView = cell.collectionView
|
||||
return cell
|
||||
}
|
||||
|
||||
func didUpdate(to object: Any) {
|
||||
override func didUpdate(to object: Any) {
|
||||
number = object as? Int
|
||||
}
|
||||
|
||||
func didSelectItem(at index: Int) {}
|
||||
override func didSelectItem(at index: Int) {}
|
||||
|
||||
// MARK: IGListAdapterDataSource
|
||||
|
||||
|
|
|
|||
|
|
@ -15,28 +15,28 @@
|
|||
import UIKit
|
||||
import IGListKit
|
||||
|
||||
final class LabelSectionController: IGListSectionController, IGListSectionType {
|
||||
final class LabelSectionController: IGListSectionController {
|
||||
|
||||
var object: String?
|
||||
|
||||
func numberOfItems() -> Int {
|
||||
override func numberOfItems() -> Int {
|
||||
return 1
|
||||
}
|
||||
|
||||
func sizeForItem(at index: Int) -> CGSize {
|
||||
override func sizeForItem(at index: Int) -> CGSize {
|
||||
return CGSize(width: collectionContext!.containerSize.width, height: 55)
|
||||
}
|
||||
|
||||
func cellForItem(at index: Int) -> UICollectionViewCell {
|
||||
override func cellForItem(at index: Int) -> UICollectionViewCell {
|
||||
let cell = collectionContext!.dequeueReusableCell(of: LabelCell.self, for: self, at: index) as! LabelCell
|
||||
cell.label.text = object
|
||||
return cell
|
||||
}
|
||||
|
||||
func didUpdate(to object: Any) {
|
||||
override func didUpdate(to object: Any) {
|
||||
self.object = String(describing: object)
|
||||
}
|
||||
|
||||
func didSelectItem(at index: Int) {}
|
||||
override func didSelectItem(at index: Int) {}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ This guide provides notes and details on best practices in using `IGListKit`, ge
|
|||
|
||||
## Best Practices
|
||||
|
||||
- We recommend adding an assert to check [`-isKindOfClass:`](https://developer.apple.com/reference/objectivec/1418956-nsobject/1418511-iskindofclass) on the object you receive in [`-didUpdateToObject:`](https://instagram.github.io/IGListKit/Protocols/IGListSectionType.html#/c:objc(pl)IGListSectionType(im)didUpdateToObject:) in your section controllers.
|
||||
- We recommend adding an assert to check [`-isKindOfClass:`](https://developer.apple.com/reference/objectivec/1418956-nsobject/1418511-iskindofclass) on the object you receive in [`-didUpdateToObject:`](https://github.com/Instagram/IGListKit/blob/master/Source/IGListSectionController.h#L63-L72) in your section controllers.
|
||||
This makes it easy to track down easily-overlooked mistakes in your [`IGListAdapaterDataSource`](https://instagram.github.io/IGListKit/Protocols/IGListAdapterDataSource.html#/c:objc(pl)IGListAdapterDataSource(im)listAdapter:sectionControllerForObject:) implementation.
|
||||
If this assert is ever hit, that means `IGListKit` has sent your section controller the incorrect type of object.
|
||||
This would only happen if your objects provide *non-unique* diff identifiers.
|
||||
|
|
|
|||
|
|
@ -8,23 +8,29 @@ After installing `IGListKit`, creating a new list is easy.
|
|||
|
||||
### Creating a section controller
|
||||
|
||||
Creating a new section controller is simple. You subclass `IGListSectionController` and conform to the `IGListSectionType` protocol. Once you conform to `IGListSectionType`, the compiler will make sure you implement all of the required methods.
|
||||
Creating a new section controller is simple. Subclass `IGListSectionController` and override at least `cellForItemAtIndex:` and `sizeForItemAtIndex:`.
|
||||
|
||||
Take a look at [LabelSectionController](https://raw.githubusercontent.com/Instagram/IGListKit/master/Examples/Examples-iOS/IGListKitExamples/SectionControllers/LabelSectionController.swift) for an example section controller that handles a `String` and configures a single cell with a `UILabel`.
|
||||
|
||||
```swift
|
||||
class LabelSectionController: IGListSectionController, IGListSectionType {
|
||||
// ...
|
||||
class LabelSectionController: IGListSectionController {
|
||||
override func sizeForItem(at index: Int) -> CGSize {
|
||||
return CGSize(width: collectionContext!.containerSize.width, height: 55)
|
||||
}
|
||||
|
||||
override func cellForItem(at index: Int) -> UICollectionViewCell {
|
||||
return collectionContext!.dequeueReusableCell(of: MyCell.self, for: self, at: index)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Creating the UI
|
||||
|
||||
After creating at least one section controller, you must create an `IGListCollectionView` and `IGListAdapter`.
|
||||
After creating at least one section controller, you must create a `UICollectionView` and `IGListAdapter`.
|
||||
|
||||
```swift
|
||||
let layout = UICollectionViewFlowLayout()
|
||||
let collectionView = IGListCollectionView(frame: .zero, collectionViewLayout: layout)
|
||||
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
|
||||
|
||||
let updater = IGListAdapterUpdater()
|
||||
let adapter = IGListAdapter(updater: updater, viewController: self, workingRangeSize: 0)
|
||||
|
|
|
|||
Loading…
Reference in a new issue