title: Nested CollectionView with dynamic height based on content whilst using MagazineLayout and Carbon
body: <p>I am creating a CollectionView where the cell has a nested CollectionView. I am using <a href="https://github.com/ra1028/Carbon" rel="nofollow noreferrer">Carbon</a> to display the cells in the collection view and using <a href="https://github.com/airbnb/MagazineLayout" rel="nofollow noreferrer">MagazineLayout</a> for the layout. There is only one Component which holds two views, a label and another CollectionView both inside of a vertical stack view with top, left, bottom and right constraints. Here is a picture of what the expected layout should be and it is similar to a &quot;thread&quot; of messages where a reply adds a new thread and so on. The nesting gets larger with more threads:</p>
  <p><a href="https://i.stack.imgur.com/8eBJS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8eBJS.png" alt="Solution Example" /></a></p>
  <p>At the moment the label displays correctly but the CollectionView height does not grow dynamically based on the cells inside of the CollectionView as shown below.</p>
  <p><a href="https://i.stack.imgur.com/g0wpr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/g0wpr.png" alt="Current" /></a></p>
  <p>I have tried using this <a href="https://medium.com/@rozan.ktm/uicollectionview-inside-uitableviewcell-dynamic-height-based-on-uicollectionviewcell-height-86b3257e85c6" rel="nofollow noreferrer">example</a> which subclasses UICollectionView and overrides layoutSubviews and intrinsicContentSize. This works to a point apart from the layout glitches and some of the nested CollectionViews heights change when scrolling.</p>
  <p>I have also looked into using UICollectionViewFlowLayout as the EstimatedItemSize can be set which does most of the heavy lifting with setting the height dynamically. However, this solution cannot be used as MagazineLayout is a subclass of UICollectionViewLayout.</p>
  <p>I can send an example project or more information if needed. Thank you for any help.</p>