1) RxDataSources is an RxSwift library that makes it easy to implement delete, insert and move operations for UITableView and UICollectionView by extracting difference updates.
2) It uses accurate difference extraction algorithms like Wagner-Fischer, Heckel and Myers under the hood.
3) The presenter demonstrates how to use RxDataSources with section models, item models and animations to build a download list feature for AbemaTV.
18. public protocol SectionModelType {
associatedtype Item
public var items: [Self.Item] { get }
public init(original: Self, items: [Self.Item])
}
RxDataSources
19. public protocol IdentifiableType {
associatedtype Identity : Hashable
public var identity: Self.Identity { get }
}
RxDataSources
28. open class RxTableViewSectionedAnimatedDataSource<S: AnimatableSectionModelType>
: TableViewSectionedDataSource<S>
, RxTableViewDataSourceType {
…
public init(
animationConfiguration: AnimationConfiguration = AnimationConfiguration(),
decideViewTransition: @escaping DecideViewTransition = { _, _, _ in .animated },
configureCell: @escaping ConfigureCell,
titleForHeaderInSection: @escaping TitleForHeaderInSection = { _, _ in nil },
titleForFooterInSection: @escaping TitleForFooterInSection = { _, _ in nil },
canEditRowAtIndexPath: @escaping CanEditRowAtIndexPath = { _, _ in false },
canMoveRowAtIndexPath: @escaping CanMoveRowAtIndexPath = { _, _ in false },
sectionIndexTitles: @escaping SectionIndexTitles = { _ in nil },
sectionForSectionIndexTitle: @escaping SectionForSectionIndexTitle = { _, _, index in index }
) {
self.animationConfiguration = animationConfiguration
self.decideViewTransition = decideViewTransition
super.init(
configureCell: configureCell,
titleForHeaderInSection: titleForHeaderInSection,
titleForFooterInSection: titleForFooterInSection,
canEditRowAtIndexPath: canEditRowAtIndexPath,
canMoveRowAtIndexPath: canMoveRowAtIndexPath,
sectionIndexTitles: sectionIndexTitles,
sectionForSectionIndexTitle: sectionForSectionIndexTitle
)
}
…
}
RxDataSources
29. final class DownloadSeriesDelegate: NSObject, UITableViewDelegate {
…
lazy var dataSource: RxTableViewSectionedAnimatedDataSource<DownloadSeriesSectionModel> = .init(
animationConfiguration: AnimationConfiguration(insertAnimation: .fade,
reloadAnimation: .none,
deleteAnimation: .fade),
configureCell: { [weak self] dataSource, table, indexPath, item in
guard let me = self else {
return UITableViewCell() // Should never reach here.
}
switch item {
case .episode(let downloadMedia):
let cell = table.dequeueReusableCell(DownloadListMediaCell.self, forIndexPath: indexPath)
cell.configure(downloadMedia: downloadMedia)
…
return cell
case .seeOtherEpisode(let series):
let cell = table.dequeueReusableCell(DownloadSeeOtherEpisodeCell.self, forIndexPath: indexPath)
cell.rx.tapGesture
.subscribe(onNext: { [weak self] in
…
})
.disposed(by: cell.reusableDisposeBag)
…
return cell
}
})
…
RxDataSources
30. final class DownloadSeriesViewStream {
…
let sectionModels: Property<[DownloadSeriesSectionModel]>
private let _sectionModels = Variable<[DownloadSeriesSectionModel]>([])
…
}
RxDataSources