mirror of
https://github.com/Instagram/IGListKit
synced 2026-04-30 18:07:44 +00:00
69 lines
2.2 KiB
Swift
69 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] {
|
||
|
|
var numbers = [Int]()
|
||
|
|
for i in 0..<(number ?? 0) {
|
||
|
|
numbers.append(i)
|
||
|
|
}
|
||
|
|
return numbers as [IGListDiffable]
|
||
|
|
}
|
||
|
|
|
||
|
|
func listAdapter(_ listAdapter: IGListAdapter, sectionControllerFor object: Any) -> IGListSectionController {
|
||
|
|
return EmbeddedSectionController()
|
||
|
|
}
|
||
|
|
|
||
|
|
func emptyView(for listAdapter: IGListAdapter) -> UIView? {
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|