Last active
May 3, 2020 09:16
-
-
Save michzio/c7c15a2eae617cb654e5f9bd773ab1db to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CollectionViewController<Section, Item>: UIViewController, UICollectionViewDelegate | |
where Section : Hashable & CaseIterable, Item : Hashable { | |
// MARK: - Injections | |
var layout: UICollectionViewLayout! = nil | |
var snapshot : NSDiffableDataSourceSnapshot<Section, Item>! = nil | |
var content: ((_ indexPath: IndexPath, _ item: Item) -> AnyView)! = nil | |
var supplementaryKinds: [String]! = nil | |
var supplementaryContent: ((_ kind: String, _ indexPath: IndexPath, _ item: Item?) -> AnyView)? = nil | |
// MARK: - Properties | |
private(set) var dataSource: UICollectionViewDiffableDataSource<Section, Item>! | |
private let diffQueue = DispatchQueue.global(qos: .background) | |
// MARK: - Views | |
lazy var collectionView: UICollectionView = { | |
let collectionView = UICollectionView(frame: view.bounds, collectionViewLayout: layout) | |
collectionView.autoresizingMask = [.flexibleHeight, .flexibleWidth] | |
collectionView.backgroundColor = .clear | |
return collectionView | |
}() | |
// MARK: - Life Cycle | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
configureCollectionView() | |
configureDataSource() | |
// load initial data | |
reloadDataSource(animating: false) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment