I am using an RxCollectionViewSectionedAnimatedDataSource. Whenever I reload the data source, and try to scroll vertically from bottom to top, the scrolling lags and looks as if some elements are getting skipped.
Here is how I have implemented things. The data source:
let dataSource = RxCollectionViewSectionedAnimatedDataSource<OfferSection>(
animationConfiguration: AnimationConfiguration(insertAnimation: .none, reloadAnimation: .none, deleteAnimation: .none), configureCell: {
[unowned self] dataSource, collectionView, indexPath, element in
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: OfferCollectionViewCell.identifier, for: indexPath) as! OffersCollectionViewCell
cell.set(offer: element)
cell.findOfferButton.rx.tap.map{indexPath}.compactMap{$0}.map{ index in
(element, index.row)}.bind(to: self.viewModel.input.viewOffer).disposed(by: cell.disposeBag)
cell.redeemButton.rx.tap.map{element}.bind(to: self.viewModel.input.redeemOffer).disposed(by: cell.disposeBag)
return cell
})
viewModel.output.offers.map{ [OfferSection(model: "", items: $0)] }.drive(self.offersCollectionView.rx.items(dataSource: dataSource)).disposed(by: disposeBag)
My OfferSection object looks like this:
typealias OfferSection = AnimatableSectionModel<String, Offer>
My Offer object conforms to Equatable
as well as IdentifiableType
, as advised in the docs.
struct Offer: IdentifiableType, Equatable {
let id: Int
let name: String
let path: String?
let offerLocation: String
let email: String?
let section: String
let categories: [String]
var identity: Int {
return id
}
To update the elements from the viewModel
, all I do is basically fetch the list of elements from the backend and use a BehaviorSubject which accepts the newly fetched list, which is then converted to a Driver and sent to the view controller as an output (viewModel.output.offers).
Any ideas?