Upgrade to Pro — share decks privately, control downloads, hide ads and more …

What's new in UICollectionView

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.

What's new in UICollectionView

Avatar for Masaki Haga

Masaki Haga

June 13, 2019
Tweet

More Decks by Masaki Haga

Other Decks in Programming

Transcript

  1. Data Source - [Old] UICollectionViewDataSource - reloadData() or performBatchUpdate(:_completion:) -

    UICollectionViewDiffableDataSource & NSDiffableDataSourceSnapshot - apply() - collectionViewへの差分反映はFramework側でhandleしてもらえるようになった。
  2. こんなかんじ struct VideoCollection: Hashable { var title: String let videos:

    [Video] let identifier = UUID() func hash(into hasher: inout Hasher) { hasher.combine(identifier) } }
  3. New API - BidrectionalColleciton: difference(from:) - Swift Standard Library: CollectionDifference

    - Foundation: NSOrderedCollectionDifference - _CollectionChanges
  4. Layout - [Old] UICollectionViewFlowLayout + UICollectionViewDelegateFlowLayout - New APIs -

    UICollectionViewCompositionalLayout - NSCollectionLayoutSection - NSCollectionLayoutGroup - NSCollectionLayoutItem - NSCollectionLayoutSize - Section > Group > Item
  5. 新しいLayoutの宣言 - UICollectionViewCompositionalLayout - initの引数として、NSCollectionLayoutSectionか、SectionProviderというClosureを渡す。 public typealias UICollectionViewCompositionalLayoutSectionProvider = (Int,

    NSCollectionLayoutEnvironment) -> NSCollectionLayoutSection? NSCollectionLayoutEnvironmentというので親CollectionViewの情報(ContentSize等)をとってくることができ る。SwiftUIでもGemetryReaderというのがあって、同じアプローチをとっているところが面白い。
  6. Nested Collection View 縦スクロールの中の横スクロールが簡単に書けるようになった。 let section = NSCollectionLayoutSection(group: group) section.orthogonalScrollingBehavior

    = .continuous UIKit側で_UICollectionViewOrthogonalScrollerEmbeddedScrollView的な ScrollViewを勝手にいれてくれる。 画面外から戻ってきてももとのContentOffsetが保存されている。