CollectionKit icon indicating copy to clipboard operation
CollectionKit copied to clipboard

All providers update after changed datasource in one provider

Open Banck opened this issue 7 years ago • 5 comments

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!

Banck avatar Aug 27 '18 09:08 Banck

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.

lkzhao avatar Sep 02 '18 02:09 lkzhao

@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 avatar Sep 24 '18 14:09 Banck

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)
            }
        }

Banck avatar Sep 24 '18 15:09 Banck

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
  }
}

lkzhao avatar Sep 26 '18 23:09 lkzhao

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

Banck avatar Sep 27 '18 05:09 Banck