Share
Embed
Updates to CollectionView in iOS14
Gubba Manoj kumar
July 21, 2020
Transcript
28 slides
-
About Me • Gubba Manoj Kumar • Github: @manoj036 •
Software Engineer at Mercari JP • Team: Personalization • Joined: October, 2018 -
CollectionView APIs After iOS 13 Diffable Data Source Compositional Layout
UICollectionViewCell/ UICollectionViewReusableView Data Layout Presentation -
CollectionView APIs iOS 14 Diffable Data Source Compositional Layout UICollectionViewCell/
UICollectionViewReusableView Data Layout Presentation Section Snapshots List Configuration List Cell View Configuration -
CollectionView APIs iOS 14 Diffable Data Source Compositional Layout UICollectionViewCell/
UICollectionViewReusableView Data Layout Presentation Section Snapshots List Configuration List Cell View Configuration -
Section Snapshots • Single Sections Data • Composable • Hierarchical
data Beta Version ScreenShot -
Section Snapshots struct NSDiffableDataSourceSectionSnapshot<Item: Hashable> { func append(_ items: [ItemIdentifierType],
to parent: ItemIdentifierType? = nil) func insert(_ items: [ItemIdentifierType], before item: ItemIdentifierType) func insert(_ items: [ItemIdentifierType], after item: ItemIdentifierType) func delete(_ items: [ItemIdentifierType]) func expand(_ items: [ItemIdentifierType]) func collapse(_ items: [ItemIdentifierType]) var items: [ItemIdentifierType] { get } var rootItems: [ItemIdentifierType] { get } func level(of item: ItemIdentifierType) -> Int } -
Section Snapshots struct NSDiffableDataSourceSectionSnapshot<Item: Hashable> { func append(_ items: [ItemIdentifierType],
to parent: ItemIdentifierType? = nil) func insert(_ items: [ItemIdentifierType], before item: ItemIdentifierType) func insert(_ items: [ItemIdentifierType], after item: ItemIdentifierType) func delete(_ items: [ItemIdentifierType]) func expand(_ items: [ItemIdentifierType]) func collapse(_ items: [ItemIdentifierType]) var items: [ItemIdentifierType] { get } var rootItems: [ItemIdentifierType] { get } func level(of item: ItemIdentifierType) -> Int } -
Section Snapshots struct NSDiffableDataSourceSectionSnapshot<Item: Hashable> { func append(_ items: [ItemIdentifierType],
to parent: ItemIdentifierType? = nil) func insert(_ items: [ItemIdentifierType], before item: ItemIdentifierType) func insert(_ items: [ItemIdentifierType], after item: ItemIdentifierType) func delete(_ items: [ItemIdentifierType]) func expand(_ items: [ItemIdentifierType]) func collapse(_ items: [ItemIdentifierType]) var items: [ItemIdentifierType] { get } var rootItems: [ItemIdentifierType] { get } func level(of item: ItemIdentifierType) -> Int } -
Reordering Support extension UICollectionViewDiffableDataSource { public struct ReorderingHandlers { public
var canReorderItem: ((Item) -> Bool)? public var willReorder: ((NSDiffableDataSourceTransaction<Section, Item>) -> Void)? public var didReorder: ((NSDiffableDataSourceTransaction<Section, Item>) -> Void)? } public var reorderingHandlers: ReorderingHandlers } -
CollectionView APIs iOS 14 Diffable Data Source Compositional Layout UICollectionViewCell/
UICollectionViewReusableView Data Layout Presentation Section Snapshots List Configuration List Cell View Configuration -
List Configuration • List Layout let configuration = UICollectionLayoutListConfiguration(appearance: .plain)
layout = UICollectionViewCompositionalLayout.list(using: configuration) • List Section Layout = UICollectionViewCompositionalLayout { (sectionIndex, layoutEnvironment) in . . . let configuration = UICollectionLayoutListConfiguration(appearance: .plain) return NSCollectionLayoutSection.list(using: configuration, layoutEnvironment: layoutEnvironment) } -
List Styles Plain Sidebar Plain Sidebar Grouped Inset Grouped Beta
Version ScreenShots -
CollectionView APIs iOS 14 Diffable Data Source Compositional Layout UICollectionViewCell/
UICollectionViewReusableView Data Layout Presentation Section Snapshots List Configuration List Cell View Configuration -
List Cell • Separators • Indentation • Swipe Actions •
Accessories Beta Version ScreenShot -
Seperators List Cell • To set the padding on separator,
• For UITableViewCell, • Separator Inset • For ListCell, • Separator Layout Guide Beta Version ScreenShot -
CollectionView APIs iOS 14 Diffable Data Source Compositional Layout UICollectionViewCell/
UICollectionViewReusableView Data Layout Presentation Section Snapshots List Configuration List Cell View Configuration -
Cell Registration • Before: collectionView.register(UICollectionViewCell.self, forCellReuseIdentifier: "CollectionViewCell") let cell =
collectionViewCell.dequeueReusableCell(withIdentifier: "CollectionViewCell", for: indexPath) as? UICollectionViewCell • After: let cellRegistration = UICollectionView.CellRegistration<UICollectionViewListCell, String> { (cell, indexPath, title) in . . . } let cell = collectionView.dequeueConfiguredReusableCell(using: cellRegistration, for: indexPath, item: “Hello") -
View configuration • Before, cell.textLabel?.text = "Title" cell.textLabel?.alignment = .center
• After, var content = UIListContentConfiguration.cell() content.text = "Title" content.textProperties.alignment = .center cell.contentConfiguration = content