5

In the brand-new and pretty neat UICollectionViewCompositionalLayout - how could the UICollectionViewLayoutAttributes be cached upon initial creation?

All the known methods and properties seem to be on-board since the new layout class inherits from UICollectionViewLayout.

Looking back to the "old" custom UICollectionViewLayout approach the path for such a task was to my knowledge to use the method prepare() to populate a(n) array(s) with custom-made [UICollectionViewLayoutAttributes].

From my understanding the new layout class creates the layout section-by- section returning -> NSCollectionLayoutSection from what we have seen as the createLayout() method in the WWDC19 talk Advances in Collection View Layout. And it seems to do that only once at initialisation.

Now, I have subclassed a UICollectionViewCompositionalLayout and the class returns layoutAttributesForElements as one would expect:

override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
        let superAttributes = super.layoutAttributesForElements(in: rect)
        print("I am returning attributes: ", supersAttributes)
        return superAttributes
}

But since they are not created manually, where can I initially catch these attributes, all at once, to add to a cache array?

The reason for this path is that I am trying to re-create a very, very -high collectionViewLayout which I need zoomable. And this only got (at least in the past) performant by using a cache, modifying cached attributes during zoon and returning layoutAttributesForElements(in: rect) from the cache all the way through the life-cycle. A technique I have seen at Ray Wenderlich´s tuturials and in other places.

Any input would be great! Let's have some fun understanding the new and easier world of wrangling collectionViews!

Thanks a lot for reading.

HelloTimo
  • 558
  • 1
  • 5
  • 18

0 Answers0