I am using a collection view compositional layout to display a cell with two labels that can grow in height, depending on the content of the labels. Everything else in the cell is fixed.
I make a section like this:
let item = NSCollectionLayoutItem(
layoutSize: NSCollectionLayoutSize(
widthDimension: .fractionalWidth(1),
heightDimension: .fractionalHeight(1)))
let group = NSCollectionLayoutGroup.vertical(
layoutSize: NSCollectionLayoutSize(
widthDimension: .fractionalWidth(1),
heightDimension: .estimated(300)),
subitems: [item])
let section = NSCollectionLayoutSection(group: group)
The problem is, it's either too big, or too small, but the correct height is never being calculated.
My assumption is that this is due to the fact that I am setting the text for the label inside a configure
method but not during the cell initialization.
let cell = collectionView.dequeueReusableCell(
reusableCell: MyCustomCell.self,
indexPath: indexPath)
cell.configure(viewModel: viewModel)
Any ideas how I can fix it? I tried invalidating the layout or reloading the data to re-calculate the height, but it didn't help.