mirror of
https://github.com/Instagram/IGListKit
synced 2026-05-03 03:17:36 +00:00
Summary: Adding a working range example to the example app. This example: - Displays a list of images downloaded from unsplash.it - Create 20 uniquely-random sized objects - When section controllers enter the range, create a data task to download the image - When finished, store image in `downloadedImage` - Set in cell if cell is visible - Don't create task if already downloaded or task created - Cancel task when section controller is destroyed - Show a spinner cell while downloading the image Fixes #84 - [x] All tests pass. Demo project builds and runs. - [x] I have reviewed the [contributing guide](https://github.com/Instagram/IGListKit/blob/master/CONTRIBUTING.md) Closes https://github.com/Instagram/IGListKit/pull/89 Differential Revision: D4050210 Pulled By: rnystrom fbshipit-source-id: 628a777fa819dccd9d9f4f58646cdf72fb4bc65c
59 lines
1.5 KiB
Swift
59 lines
1.5 KiB
Swift
//
|
|
// WorkingRangeViewController.swift
|
|
// IGListKitExamples
|
|
//
|
|
// Created by Ryan Nystrom on 10/20/16.
|
|
// Copyright © 2016 Instagram. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
import IGListKit
|
|
|
|
class WorkingRangeViewController: UIViewController, IGListAdapterDataSource {
|
|
|
|
lazy var adapter: IGListAdapter = {
|
|
return IGListAdapter(updater: IGListAdapterUpdater(), viewController: self, workingRangeSize: 2)
|
|
}()
|
|
|
|
let collectionView = IGListCollectionView(frame: CGRect.zero, collectionViewLayout: UICollectionViewFlowLayout())
|
|
|
|
let data: [Int] = {
|
|
var arr = [Int]()
|
|
while arr.count < 20 {
|
|
let int = Int(arc4random_uniform(200)) + 200
|
|
// only use unique values
|
|
if !arr.contains(int) {
|
|
arr.append(int)
|
|
}
|
|
}
|
|
return arr
|
|
}()
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
|
|
view.addSubview(collectionView)
|
|
adapter.collectionView = collectionView
|
|
adapter.dataSource = self
|
|
}
|
|
|
|
override func viewDidLayoutSubviews() {
|
|
super.viewDidLayoutSubviews()
|
|
collectionView.frame = view.bounds
|
|
}
|
|
|
|
//MARK: IGListAdapterDataSource
|
|
|
|
func objects(for listAdapter: IGListAdapter) -> [IGListDiffable] {
|
|
return data as [NSNumber]
|
|
}
|
|
|
|
func listAdapter(_ listAdapter: IGListAdapter, sectionControllerFor object: Any) -> IGListSectionController {
|
|
return WorkingRangeSectionController()
|
|
}
|
|
|
|
func emptyView(for listAdapter: IGListAdapter) -> UIView? {
|
|
return nil
|
|
}
|
|
|
|
}
|