0

I want to make cells full-width in ASCollectionNode, but I'll get CellNodes sized by content. I have implemented layoutSpecThatFits:.

See the image

Alireza
  • 193
  • 2
  • 9

1 Answers1

0

My way to achieve that is adding extra node with full width inside ASStaticLayoutSpec.

In header:

@property (strong, nonatomic) ASDisplayNode *stretchNode;

In init

_stretchNode = [ASDisplayNode new]; [self addSubnode:_stretchNode];

layoutSpecThatFits:

- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize {
    _stretchNode.sizeRange = ASRelativeSizeRangeMakeWithExactCGSize(CGSizeMake(constrainedSize.max.width, 0.5f));

    NSArray *children = @[];

    ASStackLayoutSpec *mainStackLayoutSpec = [ASStackLayoutSpec stackLayoutSpecWithDirection:ASStackLayoutDirectionVertical spacing:0 justifyContent:ASStackLayoutJustifyContentStart alignItems:ASStackLayoutAlignItemsStart children:children];
    ASStaticLayoutSpec *mainStaticLayoutSpec = [ASStaticLayoutSpec staticLayoutSpecWithChildren:@[mainInsetsLayoutSpec, _stretchNode]];

    return mainStaticLayoutSpec;
}

Important part here is to wrap your layout and stretchNode in ASStaticLayoutSpec. You can replace StackLayout with anything you want.

konradholub
  • 133
  • 9