WWDC) Advances in diffable data sources

Havi·2020년 12월 18일
0

WWDC

목록 보기
1/7

UICollectionViewDiffableDataSource를 기본적으로 알아야 합니다.

WWDC Advances in diffable data sources 영상 주소

Diffable Data Source

iOS 13에서 소개된 diffable data source는 UI state를 snapshot data type을 추가함으로써 단순화 한다.

Snapshot은 UI state를 유니크한 section과 item identifier를 통해 캡슐화한다.

따라서 UICollectionView를 update할 때, 먼저 새로운 snapshot을 만든 뒤에 현재 UI 상태로 populate 한 뒤, data source에 적용한다.

diffable data source는 differences를 계산하고, 자동적으로 animate해, 개발자가 추가적인 작업을 하지 않아도 된다.

Advanced in UI Data Source를 보면 더 자세하게 알 수 있다.

iOS14에서 Diffable Data Source의 foundation을 두 feature로 나눴다.

  1. Section Snapshot
  2. first class Reordering Support

Section Snapshot

section snapshot은 UICollectionView의 single section에 대한 data를 캡슐화한다.

이 enhancement에는 두 가지 이유가 있다.

  1. data sources를 섹션 크기의 chunk로 더 쉽게 구성 할 수 있다.
  2. Outline-style UI의 rendering을 지원하기 위한 hierachical data의 모델링을 허용하기 위해, iOS14에서 흔히 볼 수 있는 공통된 디자인이다.

snapshot은 iOS13에서 소개된 section과 item identifier를 포함하는 단어이고

section snapshot은iOS 14 타입이다.

우리는 section snapshot을 content에 추가하기 위해 append API를 사용한다.

optional parant parameter가 안주어지면 parent이고, 주어지면 child인 hierachical한 data를 만들 수 있다.

UICollectionViewDiffableDataSource에는 2개의 API가 추가되었다.

  1. apply 메소드는 section snapshot과 section identifier를 매개변수로 같는다.
  2. snapshot API는 section snapshot을 특정한 섹션의 내용을 retreive 한다.

snapshot과 section snapshot을 같이 사용하는 방법

append API를 사용하여 root에 item을 추가하고, food-parent에 emoji-child를 hierachical하게 추가한다.

다음 코드는 parent에 related된 모든 child section snapshot을 가져온다.

expansion은 section snapshot state 의 part로 관리된다.

parent expension state를 통해 child가 initially visible할지를 결정할 수 있다.

Section snapshot handlers

특정한 parent가 절대 collapse하지 않는 디자인을 만들어야할 때가 있다. 따라서 Diffable Data Source는 user interaction에 의한 programmatic한 control을 지원하는 새로운 API를 제공한다.

SectionSnapshotHandlers 프로퍼티는 struct타입으로 5가지 Optional Closure를 가지고 있다.

Collapsing을 방지하기 위해 shouldCollapseItem을 false로 반환할 수 있다.

Reordering Support

advanced Diffable data source는 우리의 콜렉션 뷰의 data를 unique item identifiers로 모델링 할 수 있게 한다.

Automatic한 reordering을 도와준다.

user가 reordering interaction을 끝내면 didReorder closure가 불린다.

reordering feature를 enable 하기 위해서는 canReorderItemdidReorder 클로저가 제공되어야 한다.

Reordering Transition

view에서 items를 reorder한 후 변경사항을 설명하는 transaction이다.

initialSnapshot은 update가 적용되기 전의 Diffable Data Source의 state이다.

finalSnapshot은 update 후 Diffable Data Source의 state이다.

array같은 데이터를 사용할 경우 difference에 직접적으로 데이터를 적용 해라.

sectionTransactions

sectionIdentifier는 이 sectionTransaction이 어떤 section에 적용될지를 가르킨다.

Example

profile
iOS Developer

0개의 댓글