RxDataSources
RxDataSources copied to clipboard
Switching between 2 different RxTableViewSectionedAnimatedDataSource
I have a table view with a viewmodel generating the data for it. I would like to be able to send along an extra info with my section data, telling wether the datasource should be forced to use deviceViewTransition.
To simplify, imaging some code like this:
let tableData: ([SectionOfCustomData], Bool) = ([
SectionOfCustomData(header: "First section", items: [CustomData(anInt: 0, aString: "zero", aCGPoint: CGPoint.zero), CustomData(anInt: 1, aString: "one", aCGPoint: CGPoint(x: 1, y: 1)) ]),
SectionOfCustomData(header: "Second section", items: [CustomData(anInt: 2, aString: "two", aCGPoint: CGPoint(x: 2, y: 2)), CustomData(anInt: 3, aString: "three", aCGPoint: CGPoint(x: 3, y: 3)) ])
],true)
static func dataSource(withReload: Bool) -> RxTableViewSectionedAnimatedDataSource<SectionOfCustomData> {
if withReload {
return RxTableViewSectionedReloadDataSource<SectionOfCustomData>(
decideViewTransition: { _, _, _ in .reload },
configureCell: { datasource, tableView, index, element in
// returns a UITablViewCell
})
} else {
return RxTableViewSectionedReloadDataSource<SectionOfCustomData>(
configureCell: { datasource, tableView, index, element in
// returns a UITablViewCell
})
}
}
Can this be done and how do I make the binding to my tableView? Usually I would do something like this:
Observable.just(tableData)
.bind(to: tableView.rx.items(dataSource: dataSource))
.disposed(by: disposeBag)
But in my case, the tableData isn't only an array of SectionOfCustomData, but also has a parameter, which should be used as input to the datasource - something like;
tableView.rx.items(dataSource: dataSource(reload: tableData.1)
Hope someone can help my out on how make this binding to my tableview - if possible at all.