apptekstudios / ASCollectionView

A SwiftUI collection view with support for custom layouts, preloading, and more.
MIT License
1.35k stars 160 forks source link

Fix AttributeGraph Cycle Issues #219

Closed robertjpayne closed 2 years ago

robertjpayne commented 2 years ago

When using ASCollectionView in a very specific way:

  1. Using an @ObservedObject as a data source for the sections
  2. Embedding SwiftUI via a UIHostingController as a child of an existing UIViewController

There are some AttributeGraph cycle warnings that appear in the logs. I've tracked these down to a nested CATransaction used to disable animations during the batch updates of the changes.

I'm not entirely sure why AttributeGraph complains about cycles and they only occur once per ASCollectionView. They also don't seem to cause any obvious issues but I'm not one to ship production code with warnings about "cycles".

In the past I've always used the UIView.performWithoutAnimation API and decided to try it instead of the CATransaction code and it still works as well as rids the AttributeGraph cycle issues.

robertjpayne commented 2 years ago

ASCollectionView.zip

Also here is an attached sample project exhibiting the error with some code that allows quick testing of the fix.

apptekstudios commented 2 years ago

Thank you, this seems to work well from my testing :) merged