CollectionKit
CollectionKit copied to clipboard
All providers update after changed datasource in one provider
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!
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 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?
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)
}
}
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
}
}
Yeah, i’ve already changed my code to like yours. Thanks.