Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1058 from Adlai-Holler/DidEndDisplayingNodeProvid…
Browse files Browse the repository at this point in the history
…eNode

Add New didEndDisplayingNode:forItemAtIndexPath: delegate methods to provide removed node
  • Loading branch information
appleguy committed Jan 14, 2016
2 parents a0c7b0a + d19e56d commit 9afb77f
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 3 deletions.
20 changes: 19 additions & 1 deletion AsyncDisplayKit/ASCollectionView.h
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,17 @@ NS_ASSUME_NONNULL_BEGIN
@optional

- (void)collectionView:(ASCollectionView *)collectionView willDisplayNodeForItemAtIndexPath:(NSIndexPath *)indexPath;
- (void)collectionView:(ASCollectionView *)collectionView didEndDisplayingNodeForItemAtIndexPath:(NSIndexPath *)indexPath;

/**
* Informs the delegate that the collection view did remove the provided node from the view hierarchy.
* This may be caused by the node scrolling out of view, or by deleting the item
* or its containing section with @c deleteItemsAtIndexPaths: or @c deleteSections: .
*
* @param collectionView The sender.
* @param node The node which was removed from the view hierarchy.
* @param indexPath The index path at which the node was located before it was removed.
*/
- (void)collectionView:(ASCollectionView *)collectionView didEndDisplayingNode:(ASCellNode *)node forItemAtIndexPath:(NSIndexPath *)indexPath;

/**
* Receive a message that the collectionView is near the end of its data set and more data should be fetched if
Expand Down Expand Up @@ -406,6 +416,14 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (BOOL)shouldBatchFetchForCollectionView:(ASCollectionView *)collectionView;

/**
* Informs the delegate that the collection view did remove the node which was previously
* at the given index path from the view hierarchy.
*
* This method is deprecated. Use @c collectionView:didEndDisplayingNode:forItemAtIndexPath: instead.
*/
- (void)collectionView:(ASCollectionView *)collectionView didEndDisplayingNodeForItemAtIndexPath:(NSIndexPath *)indexPath ASDISPLAYNODE_DEPRECATED;

@end

/**
Expand Down
10 changes: 9 additions & 1 deletion AsyncDisplayKit/ASCollectionView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -570,10 +570,18 @@ - (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICol
- (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath
{
[_rangeController visibleNodeIndexPathsDidChangeWithScrollDirection:self.scrollDirection];


if ([_asyncDelegate respondsToSelector:@selector(collectionView:didEndDisplayingNode:forItemAtIndexPath:)]) {
ASCellNode *node = ((_ASCollectionViewCell *)cell).node;
ASDisplayNodeAssertNotNil(node, @"Expected node associated with removed cell not to be nil.");
[_asyncDelegate collectionView:self didEndDisplayingNode:node forItemAtIndexPath:indexPath];
}
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
if ([_asyncDelegate respondsToSelector:@selector(collectionView:didEndDisplayingNodeForItemAtIndexPath:)]) {
[_asyncDelegate collectionView:self didEndDisplayingNodeForItemAtIndexPath:indexPath];
}
#pragma clang diagnostic pop
}

- (void)layoutSubviews
Expand Down
20 changes: 19 additions & 1 deletion AsyncDisplayKit/ASTableView.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,17 @@ NS_ASSUME_NONNULL_BEGIN
@optional

- (void)tableView:(ASTableView *)tableView willDisplayNodeForRowAtIndexPath:(NSIndexPath *)indexPath;
- (void)tableView:(ASTableView *)tableView didEndDisplayingNodeForRowAtIndexPath:(NSIndexPath *)indexPath;

/**
* Informs the delegate that the table view did remove the provided node from the view hierarchy.
* This may be caused by the node scrolling out of view, or by deleting the row
* or its containing section with @c deleteRowsAtIndexPaths:withRowAnimation: or @c deleteSections:withRowAnimation: .
*
* @param tableView The sender.
* @param node The node which was removed from the view hierarchy.
* @param indexPath The index path at which the node was located before the removal.
*/
- (void)tableView:(ASTableView *)tableView didEndDisplayingNode:(ASCellNode *)node forRowAtIndexPath:(NSIndexPath *)indexPath;

/**
* Receive a message that the tableView is near the end of its data set and more data should be fetched if necessary.
Expand Down Expand Up @@ -365,6 +375,14 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (BOOL)shouldBatchFetchForTableView:(ASTableView *)tableView;

/**
* Informs the delegate that the table view did remove the node which was previously
* at the given index path from the view hierarchy.
*
* This method is deprecated. Use @c tableView:didEndDisplayingNode:forRowAtIndexPath: instead.
*/
- (void)tableView:(ASTableView *)tableView didEndDisplayingNodeForRowAtIndexPath:(NSIndexPath *)indexPath ASDISPLAYNODE_DEPRECATED;

@end

@protocol ASTableViewDelegate <ASTableDelegate>
Expand Down
9 changes: 9 additions & 0 deletions AsyncDisplayKit/ASTableView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -598,9 +598,18 @@ - (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell

[_rangeController visibleNodeIndexPathsDidChangeWithScrollDirection:self.scrollDirection];

if ([_asyncDelegate respondsToSelector:@selector(tableView:didEndDisplayingNode:forRowAtIndexPath:)]) {
ASCellNode *node = ((_ASTableViewCell *)cell).node;
ASDisplayNodeAssertNotNil(node, @"Expected node associated with removed cell not to be nil.");
[_asyncDelegate tableView:self didEndDisplayingNode:node forRowAtIndexPath:indexPath];
}

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
if ([_asyncDelegate respondsToSelector:@selector(tableView:didEndDisplayingNodeForRowAtIndexPath:)]) {
[_asyncDelegate tableView:self didEndDisplayingNodeForRowAtIndexPath:indexPath];
}
#pragma clang diagnostic pop
}


Expand Down

0 comments on commit 9afb77f

Please sign in to comment.