IGListKit/Example/IGListKitExamples/SectionControllers/HorizontalSectionController.swift
Valeriy Van 221c2fbd20 Makes objects function more swifty.
Summary:
- [x ] All tests pass. Demo project builds and runs.
- [ ] 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 https://github.com/Instagram/IGListKit/pull/70

Reviewed By: nlutsenko

Differential Revision: D4025610

Pulled By: rnystrom

fbshipit-source-id: 927e93cec5719466dc152f82a235d5a70e53109d
2016-10-14 17:44:19 -07:00

65 lines
2.2 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
class HorizontalSectionController: IGListSectionController, IGListSectionType, IGListAdapterDataSource {
var number: Int?
lazy var adapter: IGListAdapter = {
let adapter = IGListAdapter(updater: IGListAdapterUpdater(),
viewController: self.viewController,
workingRangeSize: 0)
adapter.dataSource = self
return adapter
}()
func numberOfItems() -> Int {
return 1
}
func sizeForItem(at index: Int) -> CGSize {
return CGSize(width: collectionContext!.containerSize.width, height: 100)
}
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) {
number = object as? Int
}
func didSelectItem(at index: 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
}
}