diff --git a/examples/ASCollectionView/Sample/ViewController.m b/examples/ASCollectionView/Sample/ViewController.m index 00aea567dc..52046fd3fc 100644 --- a/examples/ASCollectionView/Sample/ViewController.m +++ b/examples/ASCollectionView/Sample/ViewController.m @@ -104,10 +104,12 @@ #pragma mark - #pragma mark ASCollectionView data source. -- (ASCellNode *)collectionView:(ASCollectionView *)collectionView nodeForItemAtIndexPath:(NSIndexPath *)indexPath +- (ASCellNodeBlock)collectionView:(ASCollectionView *)collectionView nodeBlockForItemAtIndexPath:(NSIndexPath *)indexPath; { NSString *text = [NSString stringWithFormat:@"[%zd.%zd] says hi", indexPath.section, indexPath.item]; - return [[ItemNode alloc] initWithString:text]; + return ^{ + return [[ItemNode alloc] initWithString:text]; + }; } - (ASCellNode *)collectionView:(ASCollectionView *)collectionView nodeForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath diff --git a/examples/CatDealsCollectionView/Sample/ViewController.m b/examples/CatDealsCollectionView/Sample/ViewController.m index 31a1e35435..da2a271a40 100644 --- a/examples/CatDealsCollectionView/Sample/ViewController.m +++ b/examples/CatDealsCollectionView/Sample/ViewController.m @@ -159,10 +159,12 @@ static const CGFloat kVerticalSectionPadding = 20.0f; #pragma mark - #pragma mark ASCollectionView data source. -- (ASCellNode *)collectionView:(ASCollectionView *)collectionView nodeForItemAtIndexPath:(NSIndexPath *)indexPath +- (ASCellNodeBlock)collectionView:(ASCollectionView *)collectionView nodeBlockForItemAtIndexPath:(NSIndexPath *)indexPath { ItemViewModel *viewModel = _data[indexPath.item]; - return [[ItemNode alloc] initWithViewModel:viewModel]; + return ^{ + return [[ItemNode alloc] initWithViewModel:viewModel]; + }; } - (ASCellNode *)collectionView:(UICollectionView *)collectionView nodeForSupplementaryElementOfKind:(nonnull NSString *)kind atIndexPath:(nonnull NSIndexPath *)indexPath { diff --git a/examples/CollectionViewWithViewControllerCells/Sample/ViewController.m b/examples/CollectionViewWithViewControllerCells/Sample/ViewController.m index 36f0ef5011..a9524a0d4e 100644 --- a/examples/CollectionViewWithViewControllerCells/Sample/ViewController.m +++ b/examples/CollectionViewWithViewControllerCells/Sample/ViewController.m @@ -90,16 +90,17 @@ static NSUInteger kNumberOfImages = 14; #pragma mark - #pragma mark ASCollectionView data source. -- (ASCellNode *)collectionView:(ASCollectionView *)collectionView nodeForItemAtIndexPath:(NSIndexPath *)indexPath +- (ASCellNodeBlock)collectionView:(ASCollectionView *)collectionView nodeBlockForItemAtIndexPath:(NSIndexPath *)indexPath { - ASCellNode *node = [[ASCellNode alloc] initWithViewControllerBlock:^UIViewController *{ - return [[ImageViewController alloc] initWithImage:_sections[indexPath.section][indexPath.item]]; - } didLoadBlock:nil]; - - node.layer.borderWidth = 1.0; - node.layer.borderColor = [UIColor blackColor].CGColor; - - return node; + UIImage *image = _sections[indexPath.section][indexPath.item]; + return ^{ + return [[ASCellNode alloc] initWithViewControllerBlock:^UIViewController *{ + return [[ImageViewController alloc] initWithImage:image]; + } didLoadBlock:^(ASDisplayNode * _Nonnull node) { + node.layer.borderWidth = 1.0; + node.layer.borderColor = [UIColor blackColor].CGColor; + }]; + }; } - (ASCellNode *)collectionView:(ASCollectionView *)collectionView nodeForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath diff --git a/examples/CustomCollectionView/Sample/ViewController.m b/examples/CustomCollectionView/Sample/ViewController.m index f8b6071bad..9fb81a301a 100644 --- a/examples/CustomCollectionView/Sample/ViewController.m +++ b/examples/CustomCollectionView/Sample/ViewController.m @@ -90,14 +90,18 @@ static NSUInteger kNumberOfImages = 14; #pragma mark - #pragma mark ASCollectionView data source. -- (ASCellNode *)collectionView:(ASCollectionView *)collectionView nodeForItemAtIndexPath:(NSIndexPath *)indexPath +- (ASCellNodeBlock)collectionView:(ASCollectionView *)collectionView nodeBlockForItemAtIndexPath:(NSIndexPath *)indexPath { - return [[ImageCellNode alloc] initWithImage:_sections[indexPath.section][indexPath.item]]; + UIImage *image = _sections[indexPath.section][indexPath.item]; + return ^{ + return [[ImageCellNode alloc] initWithImage:image]; + }; } + - (ASCellNode *)collectionView:(ASCollectionView *)collectionView nodeForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath { - NSString *text = [NSString stringWithFormat:@"Section %d", (int)indexPath.section + 1]; + NSString *text = [NSString stringWithFormat:@"Section %zd", indexPath.section + 1]; return [[SupplementaryNode alloc] initWithText:text]; } diff --git a/examples/HorizontalWithinVerticalScrolling/Sample/HorizontalScrollCellNode.mm b/examples/HorizontalWithinVerticalScrolling/Sample/HorizontalScrollCellNode.mm index 9eb2ee9b31..15b36b8402 100644 --- a/examples/HorizontalWithinVerticalScrolling/Sample/HorizontalScrollCellNode.mm +++ b/examples/HorizontalWithinVerticalScrolling/Sample/HorizontalScrollCellNode.mm @@ -67,11 +67,13 @@ static const CGFloat kInnerPadding = 10.0f; return 5; } -- (ASCellNode *)collectionView:(ASCollectionView *)collectionView nodeForItemAtIndexPath:(NSIndexPath *)indexPath +- (ASCellNodeBlock)collectionView:(ASCollectionView *)collectionView nodeBlockForItemAtIndexPath:(NSIndexPath *)indexPath { - RandomCoreGraphicsNode *elementNode = [[RandomCoreGraphicsNode alloc] init]; - elementNode.preferredFrameSize = _elementSize; - return elementNode; + return ^{ + RandomCoreGraphicsNode *elementNode = [[RandomCoreGraphicsNode alloc] init]; + elementNode.preferredFrameSize = _elementSize; + return elementNode; + }; } - (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize