IGListKit/Examples/Examples-iOS/IGListKitExamples/ViewControllers/AnnouncingDepsViewController.swift
dirtmelon 019b22da07 Adapts to dark mode for iOS example project. (#1453)
Summary:
## Changes in this pull request
### Checklist

- [x] All tests pass. Demo project builds and runs.
- [x] I added tests, an experiment, or detailed why my change isn't tested.
- [x] I added an entry to the `CHANGELOG.md` for any breaking changes, enhancements, or bug fixes.
- [x] I have reviewed the [contributing guide](https://github.com/Instagram/IGListKit/blob/master/.github/CONTRIBUTING.md)

Pull Request resolved: https://github.com/Instagram/IGListKit/pull/1453

Reviewed By: lorixx

Differential Revision: D23836038

Pulled By: joetam

fbshipit-source-id: 8245415992a5b1ed49f67ebfcf9f85a2745a8042
2020-10-03 01:39:08 -07:00

59 lines
1.9 KiB
Swift

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import IGListKit
import UIKit
final class AnnouncingDepsViewController: UIViewController, ListAdapterDataSource {
lazy var adapter: ListAdapter = {
return ListAdapter(updater: ListAdapterUpdater(), viewController: self, workingRangeSize: 1)
}()
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout())
let data: [NSNumber] = Array(0..<20).map { NSNumber(value: $0) }
let announcer = IncrementAnnouncer()
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(collectionView)
adapter.collectionView = collectionView
adapter.dataSource = self
// disable prefetching so cells are configured as they come on screen
if #available(iOS 10.0, *) {
collectionView.isPrefetchingEnabled = false
}
navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .add,
target: self,
action: #selector(AnnouncingDepsViewController.onAdd))
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
collectionView.frame = view.bounds
}
@objc func onAdd() {
announcer.increment()
}
// MARK: ListAdapterDataSource
func objects(for listAdapter: ListAdapter) -> [ListDiffable] {
return data
}
func listAdapter(_ listAdapter: ListAdapter, sectionControllerFor object: Any) -> ListSectionController {
return ListeningSectionController(announcer: announcer)
}
func emptyView(for listAdapter: ListAdapter) -> UIView? {
return nil
}
}