I'm having UICollectionView
with UICollectionViewCompsitionalLayout
inside UITableViewCell. collectionView is constrained to the superview using SnapKit.
After updating collectionView datasource,
collectionView.reloadData()
collectionView.layoutIfNeeded()
are called.
For dynamically changing UITableView cell, according to nested collectionView, I'm overriding intrinsicContentSize
override var intrinsicContentSize: CGSize {
let intrinsicContentSize = self.contentSize
return intrinsicContentSize
}
and overriding layoutSubviews
as well
override func layoutSubviews() {
super.layoutSubviews()
if !self.bounds.size.equalTo(self.intrinsicContentSize) {
self.invalidateIntrinsicContentSize()
}
}
}
I'm facing the issue on the first screen appear - the the height of the cell calculated incorrectly - I only see part of the the cells, but when I'm on the screen already and reload cells, everything appears correctly.
What I observe in intrinsicContentSize
contentSize -(0.0, 0.0)
contentSize -(238.0, 244.0)
contentSize -(238.0, 244.0)
contentSize -(308.0, 352.0)
contentSize -(308.0, 352.0)
cell height updates to 244.0 and every other intrinsicContentSize update is ignored. But, when I'm using UICollectionViewFlowLayout instead CompositionalLayout - intrinsicContentSize updates only twice and cell height is correct.
Of course, I can calculate the UICollectionView parent UITableView cell manually and update height accordingly in HeightForRowAtIndexPath
, but I want to avoid manual calculations.
Any suggestions, thoughts?