Skip to content

Commit be26e36

Browse files
authored
fix(ios): edge case crash on collection view refresh
1 parent 146b15b commit be26e36

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

packages/collectionview/platforms/ios/src/UICollectionViewCacheDelegateFlowLayout.m

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,21 @@ - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollection
1818
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
1919
{
2020
NSInteger index = indexPath.row;
21-
if (index < [self.cachedSizes count]) {
22-
NSValue* value = [self.cachedSizes objectAtIndex:indexPath.row];
21+
NSInteger count = [self.cachedSizes count];
22+
if (index < count) {
23+
NSValue* value = [self.cachedSizes objectAtIndex:index];
2324
if (value != nil && !CGSizeEqualToSize([value CGSizeValue], CGSizeZero)) {
2425
return [value CGSizeValue];
2526
}
26-
CGSize size = [self collectionView:collectionView layout:collectionViewLayout computedSizeForItemAtIndexPath:indexPath];
27+
}
28+
CGSize size = [self collectionView:collectionView layout:collectionViewLayout computedSizeForItemAtIndexPath:indexPath];
29+
count = [self.cachedSizes count];
30+
if (index < count) {
2731
[self.cachedSizes replaceObjectAtIndex:indexPath.row withObject:[NSValue valueWithCGSize:size]];
28-
return size;
2932
} else {
30-
CGSize size = [self collectionView:collectionView layout:collectionViewLayout computedSizeForItemAtIndexPath:indexPath];
3133
[self.cachedSizes addObject:[NSValue valueWithCGSize:size]];
32-
return size;
3334
}
35+
return size;
3436
}
3537

3638
@end

0 commit comments

Comments
 (0)