RxSwiftCommunity / RxDataSources

UITableView and UICollectionView Data Sources for RxSwift (sections, animated updates, editing ...)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RxCollectionViewSectionedAnimatedDataSource lost one cell

didanoff opened this issue · comments

I have:

let dataSource = RxCollectionViewSectionedAnimatedDataSource<CatListSection>(configureCell: {
            dataSource, collectionView, indexPath, item in
            let cell = collectionView.dequeueReusableCell(withReuseIdentifier: CatListCollectionViewCell.identifier,
                                                          for: indexPath) as! CatListCollectionViewCell
            return cell
        })
struct CatListSection {
    var header:String
    var items:[Item]
    var uniqueId: String = "Cats"
}

extension CatListSection: AnimatableSectionModelType {
    typealias Item = Cat
    typealias Identity = String
    
    init(header: String, items: [Item]) {
        self.header = header
        self.items = items
    }
    
    init(original: CatListSection, items: [Item]) {
        self = original
        self.items = items
    }
    var identity: String {
        return uniqueId
    }
}
viewModel.newCatsObservable
            .bind(to: catListCollectionView.rx.items(dataSource: dataSource))
            .disposed(by: disposeBag)

During start I send to newCatsObservable 10 items.

func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
        if indexPath.row == viewModel.catsCount - 2 {
            viewModel.loadNewCats() // Send next 10 items
        }
    }

And in collection view I see one lost cell:

Simulator Screen Shot - iPhone 8 - 2020-02-18 at 18 41 48

Why it happens?