-
Notifications
You must be signed in to change notification settings - Fork 267
Problem with ViewReuseId #164
Comments
Ok, I looked into the ViewRecycler code and now it's clear that a In our scenario we have a rather complex list view where each row can differ quite a lot from the previous rows but they are all build using the same sub components, just in different content contexts. Most of the sub components have eg. UILabels where only font and textColor is different, container views with different background colors etc and each cell can have multiple instances of these. For us it would be a big performance gain (number of views that are being re-used) if Example of a UILabel Layout that shows number of likes with let likesLayout = LabelLayout(
text: "12 likes",
font: UIFont.systemFont(ofSize: 12),
numberOfLines: 0,
viewReuseId: "labelTextColorBgColor",
config: { label in
label.textColor = .black
label.backgroundColor = UIColor.groupTableViewBackground
}
) Instead of let likesLayout = LabelLayout(
text: "12 likes",
font: UIFont.systemFont(ofSize: 12),
numberOfLines: 0,
viewReuseId: "numberOfLikesLabel",
config: { label in
label.textColor = .black
label.backgroundColor = UIColor.groupTableViewBackground
}
) The downside of this is that it would affect the LayoutKit Animation behaviour since it uses the What's your thoughts on this? |
Your observation is correct.
This is something that I experimented around with a while ago and didn't follow through with for reasons I forget. It should be possible to do what you want, but we would need two identifiers: one for uniquely identifying views for animations, and one for identifying a group of views that are interchangeable for view reuse purposes (i.e. If this is a real problem for you and you are willing to make a contribution, I would be happy to review it. |
Cool, this is something we definitely would like to have. I would be happy to make a contribution. Just need to find time to work on it, so it would probably take week or so to have a PR ready. Thanks! |
Finally got time to look into this. I've created a pull request (#175) that adds support for |
Hi,
As I understand it, you should be able to use the same
viewReuseId
for different layouts as long as they create the same UIView class and configure the same view properties. When I'm doing this and using my layouts withReloadableViewLayoutAdapter
on aUICollectionView
, it's not cleaning up views correctly on a re-usedUICollectionViewCell
.Here's a Playground example that reproduces the problem:
It initially builds a list that looks like this:
But after scrolling down and then back up it looks like this:
Ad 2 and the item below now has a yellow view that is not removed after a re-use.
The text was updated successfully, but these errors were encountered: