- Notifications
You must be signed in to change notification settings - Fork 2
Nested Collection
Anton Goncharov edited this page May 12, 2020
·
4 revisions
UITableViewCell can contain nested UICollectionView and RxDataSourcesExt let you process it in minimalistic way. To achieve it you need to create view model that implements NestedCollectionTableCellViewModel protocol
structEmbedCollectionCellViewModel:NestedCollectionTableCellViewModel{typealiasTableCellType=EmbedCollectionCellletid:StringletnestedSections:[CollectionSectionModel]letrowHeight:CGFloat=72}And UITableViewCell that implements CollectionContainableCell
classEmbedCollectionCell:UITableViewCell,ConfigurableCell,CollectionContainableCell{letcollectionView=UICollectionView()vardisposeBag=DisposeBag()func configure(with viewModel:EmbedCollectionCellViewModel){}overridefunc prepareForReuse(){
super.prepareForReuse()
disposeBag =DisposeBag()}}For processing events in a nested collection view TableDirector has some methods similar to func cellCreated() (see Events in Cells for details).
director.rx.nestedViewModelSelected(StringCollectionCell.self, in:EmbedCollectionCell.self).subscribe().disposed(by: disposeBag)
director.rx.nestedCellCreated(ButtonCollectionCell.self, in:EmbedCollectionCell.self){ $0.button.rx.tap }.subscribe().disposed(by: disposeBag)