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

All providers update after changed datasource in one provider #89

Open
Banck opened this issue Aug 27, 2018 · 5 comments
Open

All providers update after changed datasource in one provider #89

Banck opened this issue Aug 27, 2018 · 5 comments

Comments

@Banck
Copy link

Banck commented Aug 27, 2018

Hello!
Let's imagine we have ComposedProvider:
collectionView.provider = ComposedProvider(sections: [firstProvider, secondProvider])
The issue is when we've updated dataSource in firstProvider, like:
firstProviderDataSource.data = [newData]
viewUpdater and sizeSource are called for secondProvider too.
So everytime when we update data in some dataSource, all other providers will recalculate their sizeSource..
Is it right behavior?
Thanks!

@lkzhao
Copy link
Collaborator

lkzhao commented Sep 2, 2018

It is the current behaviour.
There is room for optimization here by caching the size for each sections in ComposedProvider, and not forcing every sub-provider to layout. But it doesn't work for all layouts, because the layout of the second provider might have changed in response of the size change.

@Banck
Copy link
Author

Banck commented Sep 24, 2018

@lkzhao is there any solution now?
I have collectionView with 2 providers: First is info Cell, the second cell is Video cell (webview/player).

ComposedProvider(layout: RowLayout().insetVisibleFrame(by: visibleFrameInsets),
                                         sections: [infoProvider, videoProvider])

They have different dataSources:

    var dataSource: ArrayDataSource<Match> = ArrayDataSource<Match>()
    var videoDataSource: ArrayDataSource<String> = ArrayDataSource<String>()

but when I'm in the second cell and my info dataSource is updated (which updated every n seconds), my video stops, because second cell is updating too..
What can we do?

@Banck
Copy link
Author

Banck commented Sep 24, 2018

In my case, where I have only 1 cell in each provider I can update cell in cellUpdater if there is no link before:

            let cellUpdate = { (cell: WebViewCell, data: String, at: Int) in
            let url = URL(string: data)!
            if cell.webView.url == nil {
                cell.configure(with: url)
            }
        }

@lkzhao
Copy link
Collaborator

lkzhao commented Sep 26, 2018

Yes, this is the suggested solution to this problem.

What I usually do is something like this:

class MyCell: UIView {
  var url: URL?
  func configure(with url: URL) {
    guard self.url != url else { return }
    // do your magic
  }
}

@Banck
Copy link
Author

Banck commented Sep 27, 2018

Yeah, i’ve already changed my code to like yours.
Thanks.

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