Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switching between 2 different RxTableViewSectionedAnimatedDataSource #347

Open
usk78dk opened this issue Dec 5, 2019 · 1 comment
Open

Comments

@usk78dk
Copy link

usk78dk commented Dec 5, 2019

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.

@nickfl
Copy link

nickfl commented Jan 22, 2020

Worth to look at this dissuasion

or specifically this Code sample

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants