TLDR; Depending on the section, I need the cells to be sized either:
- Fixed width but dynamic height (for example, full screen width with automatic height depending on the content)
- Dynamic width but fixed height (1st cell could be 120pt wide, 2nd cell could be 155pt wide, etc..)
Here is a pictogram of what we need to clear any ambiguity that might exists.
I am looking for simply: "Yes, you can achieve this with compositional layout and here is how...". Or "No, you cannot implement this with compositional, you must use flow layout or some other custom layout."
Couple of additional requirements:
- Proposed solution should NOT recommend using collectionView(_:layout:sizeForItemAt:) with flow layout because that is the thing we are trying to avoid. If that is the answer, then you may simply say - "No, this cannot be achieved with compositional layouts".
- Proposed solution should let the collection view figure out how to lay the cells appropriately based on their intrinsic content size. This is akin to using tableview's dynamic self sizing capability by
UITableViewAutomaticDimension
Background info:
- It is clear how to implement full width but dynamic height cells using compositional layout. See this exchange.
- Known limitations of the flow layout with automatic content size are documented here and here. That is the guy who wrote one of the O'Reilly books. Basically he says that there is no really auto-sizing flow layout even though Apple claims that there is. Hence the quest to try to solve this problem with the Compositional layout.