I have a collection view in my app, and it would refresh with animation when there is new content or deletion. However, I don't want it to refresh while user is scrolling because it would cause jerking. I want to refresh the collection view only when user has finished scrolling / when it's not scrolling.
So I have a data source driver, and I tried to use filter
to make it wait till it becomes true but no luck.
This is my scrolling driver that I pass to the ViewModel
let isScrollViewScrollingDriver = Observable.merge(
gridCollectionView.rx.willBeginDragging.map { _ in true },
gridCollectionView.rx.didEndDragging.map { _ in false }
).asDriver(onErrorJustReturn: false).startWith(false).distinctUntilChanged()
my ViewModel init in view controller
viewModel = ViewModel(
photoLibraryService: PhotoLibraryService.shared,
isGridViewScrolling: isScrollViewScrollingDriver,
disposeBag: disposeBag
)
My ViewModel
let assetDriver = photoLibraryService.albumDriver.asObservable()
.withLatestFrom(
isGridViewScrolling.asObservable().filter { $0 == false }
) { (arg0, arg1) in
return arg0
}.flatMapLatest { libraryAlbum -> Observable<[LibraryAsset]> in
return photoLibraryService.convert(album: libraryAlbum)
}.asDriver(onErrorJustReturn: []).startWith([]).distinctUntilChanged()
And then I map assetDriver to a dataSourceDriver that drive my collection view.
What changes can I make to the assetDriver to make it wait for isGridViewScrolling
to become false
? Thanks.