Skip to content

Commit

Permalink
Check for nil elements on ASTableView as well #trivial (TextureGroup#710
Browse files Browse the repository at this point in the history
)
  • Loading branch information
cestebanez authored and bernieperez committed Apr 25, 2018
1 parent b017f4a commit 0908311
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Source/ASCollectionView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,7 @@ - (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICol
ASCellNode *cellNode = element.node;
cellNode.scrollView = collectionView;

// Update the selected background view in collectionView:willDisplayCell:forItemAtIndexPath: otherwise it could be to
// Update the selected background view in collectionView:willDisplayCell:forItemAtIndexPath: otherwise it could be too
// early e.g. if the selectedBackgroundView was set in didLoad()
cell.selectedBackgroundView = cellNode.selectedBackgroundView;

Expand Down
29 changes: 26 additions & 3 deletions Source/ASTableView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ - (void)setElement:(ASCollectionElement *)element
[node __setHighlightedFromUIKit:self.highlighted];
}

- (BOOL)consumesCellNodeVisibilityEvents
{
ASCellNode *node = self.node;
if (node == nil) {
return NO;
}
return ASSubclassOverridesSelector([ASCellNode class], [node class], @selector(cellNodeVisibilityEvent:inScrollView:withCellFrame:));
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
Expand Down Expand Up @@ -971,7 +980,14 @@ - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sou
- (void)tableView:(UITableView *)tableView willDisplayCell:(_ASTableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
ASCollectionElement *element = cell.element;
[_visibleElements addObject:element];
if (element) {
ASDisplayNodeAssertTrue([_dataController.visibleMap elementForItemAtIndexPath:indexPath] == element);
[_visibleElements addObject:element];
} else {
ASDisplayNodeAssert(NO, @"Unexpected nil element for willDisplayCell: %@, %@, %@", cell, self, indexPath);
return;
}

ASCellNode *cellNode = element.node;
cellNode.scrollView = tableView;

Expand All @@ -991,15 +1007,22 @@ - (void)tableView:(UITableView *)tableView willDisplayCell:(_ASTableViewCell *)c

[_rangeController setNeedsUpdate];

if (ASSubclassOverridesSelector([ASCellNode class], [cellNode class], @selector(cellNodeVisibilityEvent:inScrollView:withCellFrame:))) {
if ([cell consumesCellNodeVisibilityEvents]) {
[_cellsForVisibilityUpdates addObject:cell];
}
}

- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(_ASTableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
// Retrieve the element from cell instead of visible map because at this point visible map could have been updated and no longer holds the element.
ASCollectionElement *element = cell.element;
[_visibleElements removeObject:element];
if (element) {
[_visibleElements removeObject:element];
} else {
ASDisplayNodeAssert(NO, @"Unexpected nil element for didEndDisplayingCell: %@, %@, %@", cell, self, indexPath);
return;
}

ASCellNode *cellNode = element.node;

[_rangeController setNeedsUpdate];
Expand Down

0 comments on commit 0908311

Please sign in to comment.