mirror of
https://github.com/Instagram/IGListKit
synced 2026-04-30 01:47:18 +00:00
Summary: Removing the `IGListSectionType` protocol and adding default implementations into `IGListSectionController`. - `numberOfItems` returns 1 - `cellForItemAtIndex:` asserts (have to return a cell) - `didUpdateToObject:` no-ops - `didSelectItemAtIndex:` no-ops Fixes #168 Reviewed By: jessesquires Differential Revision: D4909585 fbshipit-source-id: 8816702504e3fc0683868914ff4dd20e4af7c166
59 lines
2.1 KiB
Swift
59 lines
2.1 KiB
Swift
/**
|
|
Copyright (c) 2016-present, Facebook, Inc. All rights reserved.
|
|
|
|
The examples provided by Facebook are for non-commercial testing and evaluation
|
|
purposes only. Facebook reserves all rights not expressly granted.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
*/
|
|
|
|
import UIKit
|
|
import IGListKit
|
|
|
|
final class HorizontalSectionController: IGListSectionController, IGListAdapterDataSource {
|
|
|
|
private var number: Int?
|
|
|
|
lazy var adapter: IGListAdapter = {
|
|
let adapter = IGListAdapter(updater: IGListAdapterUpdater(),
|
|
viewController: self.viewController,
|
|
workingRangeSize: 0)
|
|
adapter.dataSource = self
|
|
return adapter
|
|
}()
|
|
|
|
override func sizeForItem(at index: Int) -> CGSize {
|
|
return CGSize(width: collectionContext!.containerSize.width, height: 100)
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
override func didUpdate(to object: Any) {
|
|
number = object as? Int
|
|
}
|
|
|
|
//MARK: IGListAdapterDataSource
|
|
|
|
func objects(for listAdapter: IGListAdapter) -> [IGListDiffable] {
|
|
guard let number = number else { return [] }
|
|
return (0..<number).map { $0 as IGListDiffable }
|
|
}
|
|
|
|
func listAdapter(_ listAdapter: IGListAdapter, sectionControllerFor object: Any) -> IGListSectionController {
|
|
return EmbeddedSectionController()
|
|
}
|
|
|
|
func emptyView(for listAdapter: IGListAdapter) -> UIView? {
|
|
return nil
|
|
}
|
|
|
|
}
|