I need to use compositional format to create a easy listing assortment view — cells are 100% width, and their peak is dynamic primarily based on their content material. The content material of every cell might be a group view that can occupy the total width of its mum or dad cell and its peak must be dynamic primarily based on its content material, and the ensuing peak of it ought to decide the peak of the mum or dad cell that comprises it.
I am presently utilizing this format for the listing view:
static func autoListLayout(rowHeight: CGFloat, padding: CGFloat) -> UICollectionViewLayout {
let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: .estimated(rowHeight))
let merchandise = NSCollectionLayoutItem(layoutSize: itemSize)
merchandise.contentInsets = NSDirectionalEdgeInsets.zero
let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: .fractionalHeight(1))
let group = NSCollectionLayoutGroup.vertical(layoutSize: groupSize, subitems: [item])
group.interItemSpacing = .mounted(padding)
let part = NSCollectionLayoutSection(group: group)
part.orthogonalScrollingBehavior = .none
part.contentInsets = NSDirectionalEdgeInsets(high: padding, main: 0, backside: padding, trailing: 0)
part.interGroupSpacing = padding
let format = UICollectionViewCompositionalLayout(part: part)
return format
}
And the gathering view being added into the cells of this listing seems to be like this:
addSubview(subCollectionView)
subCollectionView.isScrollEnabled = false
subCollectionView.translatesAutoresizingMaskIntoConstraints = false
subCollectionView.setContentHuggingPriority(.required, for: .vertical)
subCollectionView.setContentCompressionResistancePriority(.required, for: .vertical)
NSLayoutConstraint.activate([
subCollectionView.leftAnchor.constraint(equalTo: leftAnchor),
subCollectionView.rightAnchor.constraint(equalTo: rightAnchor),
subCollectionView.topAnchor.constraint(equalTo: topAnchor),
subCollectionView.bottomAnchor.constraint(equalTo: bottomAnchor),
])
And the format for that assortment view as constructed as follows:
static func subLayout(rowHeight: CGFloat, padding: CGFloat) -> UICollectionViewLayout {
let itemSize = NSCollectionLayoutSize(widthDimension: .estimated(30), heightDimension: .estimated(rowHeight))
let merchandise = NSCollectionLayoutItem(layoutSize: itemSize)
merchandise.contentInsets = NSDirectionalEdgeInsets.zero
let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: .fractionalHeight(1))
let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, subitems: [item])
group.interItemSpacing = .mounted(padding)
let part = NSCollectionLayoutSection(group: group)
part.orthogonalScrollingBehavior = .none
let format = UICollectionViewCompositionalLayout(part: part)
return format
}
This isn’t ensuing within the right sizing although. The gathering view inside the cells shouldn’t be sizing to suit its content material and the cell that comprises it’s thus not being sized to suit the gathering view inside (as a result of the inner assortment view has a ensuing peak of 0)
I understand that compositional format is meant to eradicate the necessity for nesting assortment views on this method however I’ve a use case the place it might be useful if I might do it this manner.
Any concepts?