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

Advances in CollectionViews

Advances in CollectionViews

The talk covers the new layout included in iOS 13. The compositional layout which enables you to create complex layouts without writing a lot of boilerplate code.
Demo Link: https://github.com/rahuljain01/CompositionalLayout

Speakers: Vinita Miranda & Rahul Jain
Vinita has 7.5+ years of experience in iOS. Currently working as an iOS Developer at Dream11.
LinkedIn: https://www.linkedin.com/in/vinita-miranda-3874a824
Rahul Jain: https://www.linkedin.com/in/rahuljain01/

Presented at Swift Mumbai Chapter 9 Meetup hosted by Dream11
https://www.meetup.com/Swift-Mumbai/events/260541095/

Eeb061c8b2816b771920da1b3e7904a3?s=128

Swift India

June 22, 2019
Tweet

Transcript

  1. Compositional Layouts - Vinita Miranda & Rahul Jain

  2. Weekly Leaderboard

  3. Current Approach • Multiple collection view • Abstract classes •

    Line based layout.
  4. Custom Layout Challenges • Boilerplate Code • Supplementary/ Decorations Views

    • Self-sizing challenges
  5. Compositional Layout • Composible • Flexible • Fast

  6. Compositional Layout • Composing small layouts • Line based layout

    • Composition instead of subclassing
  7. Components in Compositional Layout • NSCollectionLayoutSize • NSCollectionLayoutItem • NSCollectionLayoutGroup

    • NSCollectionLayoutSection • NSCollectionViewCompositionalLayout
  8. None
  9. Item -> Group -> Section -> Layout Layout Section Group

    Item
  10. NSCollectionLayoutSize • Width • Height

  11. NSCollectionLayoutDimension

  12. Fractional Width 0.5

  13. NSCollectionLayoutDimension

  14. 200

  15. None
  16. NSCollectionLayoutItem

  17. NSCollectionLayoutGroup

  18. NSCollectionLayoutSection

  19. UICollectionViewCompositionalLayout

  20. Current Collection Data Source

  21. Controller UI Number of items Web Service Response Did Change

  22. Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update:

    invalid number of sections. The number of sections contained in the collection view after the update (10) must be equal to the number of sections contained in the collection view before the update (10), plus or minus the number of sections inserted or deleted (0 inserted, 1 deleted).
  23. UICollectionViewDiffableDataSource • Apply is used instead of performBatchUpdates.

  24. NSDiffableDataSourceSnapshot • Unique identifiers for section and items. • No

    indexPath needed
  25. Identifiers • Must be unique • Must conform to hashable

  26. Demo