Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate example projects to the recommended -nodeBlock data source method #1596

Merged
merged 1 commit into from
Jul 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions examples/ASDKTube/Sample/Controller/VideoFeedNodeController.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ - (NSInteger)tableNode:(ASTableNode *)tableNode numberOfRowsInSection:(NSInteger
return _videoFeedData.count;
}

- (ASCellNode *)tableNode:(ASTableNode *)tableNode nodeForRowAtIndexPath:(NSIndexPath *)indexPath
{
- (ASCellNodeBlock)tableNode:(ASTableNode *)tableNode nodeBlockForRowAtIndexPath:(NSIndexPath *)indexPath {
VideoModel *videoObject = [_videoFeedData objectAtIndex:indexPath.row];
VideoContentCell *cellNode = [[VideoContentCell alloc] initWithVideoObject:videoObject];

return cellNode;
return ^{
VideoContentCell *cellNode = [[VideoContentCell alloc] initWithVideoObject:videoObject];
return cellNode;
};
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ class ViewController: ASViewController<ASCollectionNode>, MosaicCollectionViewLa
_collectionNode.view.isScrollEnabled = true
}

func collectionNode(_ collectionNode: ASCollectionNode, nodeForItemAt indexPath: IndexPath) -> ASCellNode {
func collectionNode(_ collectionNode: ASCollectionNode, nodeBlockForItemAt indexPath: IndexPath) -> ASCellNodeBlock {
let image = _sections[indexPath.section][indexPath.item]
return ImageCellNode(with: image)
return {
return ImageCellNode(with: image)
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ - (void)reloadEverything

#pragma mark - ASTableNode

- (ASCellNode *)tableNode:(ASTableNode *)tableNode nodeForRowAtIndexPath:(NSIndexPath *)indexPath
{
return [[HorizontalScrollCellNode alloc] initWithElementSize:CGSizeMake(100, 100)];
- (ASCellNodeBlock)tableNode:(ASTableNode *)tableNode nodeBlockForRowAtIndexPath:(NSIndexPath *)indexPath {
return ^{
return [[HorizontalScrollCellNode alloc] initWithElementSize:CGSizeMake(100, 100)];
};
}

- (NSInteger)tableNode:(ASTableNode *)tableNode numberOfRowsInSection:(NSInteger)section
Expand Down
15 changes: 9 additions & 6 deletions examples/Kittens/Sample/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,20 @@ - (NSInteger)tableNode:(ASTableNode *)tableNode numberOfRowsInSection:(NSInteger
return 1 + _kittenDataSource.count;
}

- (ASCellNode *)tableNode:(ASTableNode *)tableNode nodeForRowAtIndexPath:(NSIndexPath *)indexPath
{
- (ASCellNodeBlock)tableNode:(ASTableNode *)tableNode nodeBlockForRowAtIndexPath:(NSIndexPath *)indexPath {
// special-case the first row
if ([_blurbNodeIndexPath compare:indexPath] == NSOrderedSame) {
BlurbNode *node = [[BlurbNode alloc] init];
return node;
return ^{
BlurbNode *node = [[BlurbNode alloc] init];
return node;
};
}

NSValue *size = _kittenDataSource[indexPath.row - 1];
KittenNode *node = [[KittenNode alloc] initWithKittenOfSize:size.CGSizeValue];
return node;
return ^{
KittenNode *node = [[KittenNode alloc] initWithKittenOfSize:size.CGSizeValue];
return node;
};
}

- (void)tableNode:(ASTableNode *)tableNode didSelectRowAtIndexPath:(NSIndexPath *)indexPath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,11 @@ extension OverviewViewController: ASTableDataSource {
return layoutExamples.count
}

func tableNode(_ tableNode: ASTableNode, nodeForRowAt indexPath: IndexPath) -> ASCellNode {
return OverviewCellNode(layoutExampleType: layoutExamples[indexPath.row])
func tableNode(_ tableNode: ASTableNode, nodeBlockForRowAt indexPath: IndexPath) -> ASCellNodeBlock {
let layoutExample = layoutExamples[indexPath.row]
return {
return OverviewCellNode(layoutExampleType: layoutExample)
}
}
}

Expand Down
8 changes: 5 additions & 3 deletions examples/LayoutSpecExamples/Sample/OverviewViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ - (NSInteger)tableNode:(ASTableNode *)tableNode numberOfRowsInSection:(NSInteger
return [_layoutExamples count];
}

- (ASCellNode *)tableNode:(ASTableNode *)tableNode nodeForRowAtIndexPath:(NSIndexPath *)indexPath
{
return [[OverviewCellNode alloc] initWithLayoutExampleClass:_layoutExamples[indexPath.row]];
- (ASCellNodeBlock)tableNode:(ASTableNode *)tableNode nodeBlockForRowAtIndexPath:(NSIndexPath *)indexPath {
Class layoutExample = _layoutExamples[indexPath.row];
return ^{
return [[OverviewCellNode alloc] initWithLayoutExampleClass:layoutExample];
};
}

- (void)tableNode:(ASTableNode *)tableNode didSelectRowAtIndexPath:(NSIndexPath *)indexPath
Expand Down
21 changes: 12 additions & 9 deletions examples/Swift/Sample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,24 @@ final class ViewController: ASViewController<ASDisplayNode>, ASTableDataSource,

// MARK: ASTableNode data source and delegate.

func tableNode(_ tableNode: ASTableNode, nodeForRowAt indexPath: IndexPath) -> ASCellNode {
func tableNode(_ tableNode: ASTableNode, nodeBlockForRowAt indexPath: IndexPath) -> ASCellNodeBlock {
// Should read the row count directly from table view but
// https://github.com/facebook/AsyncDisplayKit/issues/1159
let rowCount = self.tableNode(tableNode, numberOfRowsInSection: 0)

if state.fetchingMore && indexPath.row == rowCount - 1 {
let node = TailLoadingCellNode()
node.style.height = ASDimensionMake(44.0)
return node;
return {
let node = TailLoadingCellNode()
node.style.height = ASDimensionMake(44.0)
return node;
}
}

return {
let node = ASTextCellNode()
node.text = String(format: "[%ld.%ld] says hello!", indexPath.section, indexPath.row)
return node
}

let node = ASTextCellNode()
node.text = String(format: "[%ld.%ld] says hello!", indexPath.section, indexPath.row)

return node
}

func numberOfSections(in tableNode: ASTableNode) -> Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,14 @@ - (void)viewWillLayoutSubviews
#pragma mark -
#pragma mark ASPagerNode.

- (ASCellNode *)pagerNode:(ASPagerNode *)pagerNode nodeAtIndex:(NSInteger)index
{
- (ASCellNodeBlock)pagerNode:(ASPagerNode *)pagerNode nodeBlockAtIndex:(NSInteger)index {
CGSize boundsSize = pagerNode.bounds.size;
CGSize gradientRowSize = CGSizeMake(boundsSize.width, 100);
GradientTableNode *node = [[GradientTableNode alloc] initWithElementSize:gradientRowSize];
node.pageNumber = index;
return node;
return ^{
GradientTableNode *node = [[GradientTableNode alloc] initWithElementSize:gradientRowSize];
node.pageNumber = index;
return node;
};
}

- (ASSizeRange)pagerNode:(ASPagerNode *)pagerNode constrainedSizeForNodeAtIndex:(NSInteger)index;
Expand Down