Texture icon indicating copy to clipboard operation
Texture copied to clipboard

Can't resize Cell Node when using UICollectionViewCompositionalLayout

Open mycroftcanner opened this issue 4 years ago • 0 comments

I am trying to use a UICollectionViewCompositionalLayout with a AScollectionNode. However layoutSpecThatFits's constrained size ends up being :

ASSizeRange(394.0, 300.0), max: (394.0, 300.0)

and my layout can't shrink.

my cell node layout:

    let stack = ASStackLayoutSpec.vertical()
    stack.style.flexShrink = 1.0
    stack.style.flexGrow = 1.0
    stack.spacing = .fp_grid(2)
    
    if let imageSpec = imageLayout(constrainedSize) {
      stack.children?.append(imageSpec)
    }
    
    let titlenodes = [titleNode, subtitleNode].compactMap { $0 }
    
    if !titlenodes.isEmpty {
      let titleStack = ASStackLayoutSpec.vertical()
      titleStack.spacing = .fp_grid(0.1)
      titleStack.children = titlenodes
      stack.children?.append(titleStack)
    }
    
    if let summaryNode = summaryNode {
      stack.children?.append(summaryNode)
    }
    return stack

This is my UICollectionViewCompositionalLayout:

  public static func createDetailedLayout() -> UICollectionViewCompositionalLayout {
    let estimatedHeight = CGFloat(300)
    
    let layoutSize = NSCollectionLayoutSize(
      widthDimension: .fractionalWidth(1.0),
      heightDimension: .estimated(estimatedHeight))
    
    let item = NSCollectionLayoutItem(layoutSize: layoutSize)
    
    let group = NSCollectionLayoutGroup.horizontal(
      layoutSize: layoutSize,
      subitem: item,
      count: 1
    )
    
    let section = NSCollectionLayoutSection(group: group)
    section.contentInsets = NSDirectionalEdgeInsets(top: 10, leading: 10, bottom: 10, trailing: 10)
    section.interGroupSpacing = 10
    
    let layout = UICollectionViewCompositionalLayout(section: section)
    return layout
  }

mycroftcanner avatar Jul 04 '21 01:07 mycroftcanner