Skip to content

Instantly share code, notes, and snippets.

@michzio
Last active May 3, 2020 10:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michzio/0b1e5117ce19fed467e325a06cc20d57 to your computer and use it in GitHub Desktop.
Save michzio/0b1e5117ce19fed467e325a06cc20d57 to your computer and use it in GitHub Desktop.
struct CollectionView<Section: Hashable & CaseIterable, Item: Hashable>: UIViewControllerRepresentable {
// MARK: - Properties
let layout: UICollectionViewLayout
let sections: [Section]
let items: [Section: [Item]]
let supplementaryKinds: [String]
let animateChanges: Bool?
// MARK: - Actions
let content: (_ indexPath: IndexPath, _ item: Item) -> AnyView
let snapshot: (() -> NSDiffableDataSourceSnapshot<Section, Item>)?
let supplementaryContent: ((_ kind: String, _ indexPath: IndexPath, _ item: Item?) -> AnyView)?
init(layout: UICollectionViewLayout,
sections: [Section],
items: [Section: [Item]],
snapshot: (() -> NSDiffableDataSourceSnapshot<Section, Item>)? = nil,
supplementaryKinds: [String] = [],
animateChanges: Bool? = nil,
supplementaryContent: ((_ kind: String, _ IndexPath: IndexPath, _ item: Item?) -> AnyView)? = nil,
@ViewBuilder content: @escaping (_ indexPath: IndexPath, _ item: Item) -> AnyView) {
self.layout = layout
self.sections = sections
self.items = items
self.snapshot = snapshot
self.animateChanges = animateChanges
self.supplementaryKinds = supplementaryKinds
self.supplementaryContent = supplementaryContent
self.content = content
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment