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

[ASCollectionView] Copy _cellsForVisibilityUpdates During Callback for Safety #1413

Closed
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: 4 additions & 6 deletions AsyncDisplayKit/ASCollectionView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -590,11 +590,9 @@ - (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(
ASDisplayNodeAssertNotNil(cellNode, @"Expected node associated with removed cell not to be nil.");
[_asyncDelegate collectionView:self didEndDisplayingNode:cellNode forItemAtIndexPath:indexPath];
}

if ([_cellsForVisibilityUpdates containsObject:cell]) {
[_cellsForVisibilityUpdates removeObject:cell];
}


[_cellsForVisibilityUpdates removeObject:cell];

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
if ([_asyncDelegate respondsToSelector:@selector(collectionView:didEndDisplayingNodeForItemAtIndexPath:)]) {
Expand Down Expand Up @@ -727,7 +725,7 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView
[_rangeController updateCurrentRangeWithMode:ASLayoutRangeModeFull];
}

for (_ASCollectionViewCell *collectionCell in _cellsForVisibilityUpdates) {
for (_ASCollectionViewCell *collectionCell in [_cellsForVisibilityUpdates copy]) {
// Only nodes that respond to the selector are added to _cellsForVisibilityUpdates
[[collectionCell node] cellNodeVisibilityEvent:ASCellNodeVisibilityEventVisibleRectChanged
inScrollView:scrollView
Expand Down
6 changes: 2 additions & 4 deletions AsyncDisplayKit/ASTableView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView
[_rangeController updateCurrentRangeWithMode:ASLayoutRangeModeFull];
}

for (_ASTableViewCell *tableCell in _cellsForVisibilityUpdates) {
for (_ASTableViewCell *tableCell in [_cellsForVisibilityUpdates copy]) {
[[tableCell node] cellNodeVisibilityEvent:ASCellNodeVisibilityEventVisibleRectChanged
inScrollView:scrollView
withCellFrame:tableCell.frame];
Expand Down Expand Up @@ -657,9 +657,7 @@ - (void)tableView:(UITableView *)tableView didEndDisplayingCell:(_ASTableViewCel
[_asyncDelegate tableView:self didEndDisplayingNode:cellNode forRowAtIndexPath:indexPath];
}

if ([_cellsForVisibilityUpdates containsObject:cell]) {
[_cellsForVisibilityUpdates removeObject:cell];
}
[_cellsForVisibilityUpdates removeObject:cell];

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
Expand Down