Skip to content

Commit

Permalink
ASCollectionLayout needs to set size to measured cells (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenhuy authored and Adlai-Holler committed Apr 19, 2017
1 parent 7c86faf commit ed5a139
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions Source/Private/ASCollectionLayout.mm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import <AsyncDisplayKit/ASCollectionLayout.h>

#import <AsyncDisplayKit/ASAssert.h>
#import <AsyncDisplayKit/ASCellNode.h>
#import <AsyncDisplayKit/ASCollectionElement.h>
#import <AsyncDisplayKit/ASCollectionLayoutContext+Private.h>
#import <AsyncDisplayKit/ASCollectionLayoutDelegate.h>
Expand Down Expand Up @@ -116,6 +117,7 @@ - (CGSize)collectionViewContentSize
for (ASCollectionElement *element in attrsMap) {
UICollectionViewLayoutAttributes *attrs = [attrsMap objectForKey:element];
if (CGRectIntersectsRect(rect, attrs.frame)) {
[ASCollectionLayout setSize:attrs.frame.size toElement:element];
[attributesInRect addObject:attrs];
}
}
Expand All @@ -126,18 +128,32 @@ - (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSInde
{
ASCollectionLayoutState *state = _state;
ASCollectionElement *element = [state.elements elementForItemAtIndexPath:indexPath];
return [state.elementToLayoutArrtibutesMap objectForKey:element];
UICollectionViewLayoutAttributes *attrs = [state.elementToLayoutArrtibutesMap objectForKey:element];
[ASCollectionLayout setSize:attrs.frame.size toElement:element];
return attrs;
}

- (UICollectionViewLayoutAttributes *)layoutAttributesForSupplementaryViewOfKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath
{
ASCollectionLayoutState *state = _state;
ASCollectionElement *element = [state.elements supplementaryElementOfKind:elementKind atIndexPath:indexPath];
return [state.elementToLayoutArrtibutesMap objectForKey:element];
UICollectionViewLayoutAttributes *attrs = [state.elementToLayoutArrtibutesMap objectForKey:element];
[ASCollectionLayout setSize:attrs.frame.size toElement:element];
return attrs;
}

#pragma mark - Private methods

+ (void)setSize:(CGSize)size toElement:(ASCollectionElement *)element
{
ASCellNode *node = element.node;
if (! CGSizeEqualToSize(size, node.frame.size)) {
CGRect nodeFrame = CGRectZero;
nodeFrame.size = size;
node.frame = nodeFrame;
}
}

- (CGSize)viewportSize
{
ASCollectionNode *collectionNode = _collectionNode;
Expand Down

0 comments on commit ed5a139

Please sign in to comment.