mirror of
https://github.com/Instagram/IGListKit
synced 2026-05-23 09:18:29 +00:00
Safely check the sectionIndex to be within the right bound before converting to use convertSectionReloadToItemUpdates
Summary: This made the items reload safer, as I tested that passing in an out-of-bound section index to -[UICollectionView numberOfItemsInSection:] would crash the app. UIKit did not handle this gracefully. Reviewed By: calimarkus Differential Revision: D9624061 fbshipit-source-id: bcf14a3d4746b648046992adf221faff36a0257c
This commit is contained in:
parent
66742f2309
commit
eddb0a5f21
1 changed files with 3 additions and 1 deletions
|
|
@ -330,7 +330,9 @@ static NSArray<NSIndexPath *> *convertSectionReloadToItemUpdates(NSIndexSet *sec
|
|||
if (self.preferItemReloadsForSectionReloads) {
|
||||
[reloads enumerateIndexesUsingBlock:^(NSUInteger sectionIndex, BOOL * _Nonnull stop) {
|
||||
NSMutableIndexSet *localIndexSet = [NSMutableIndexSet indexSetWithIndex:sectionIndex];
|
||||
if ([collectionView numberOfItemsInSection:sectionIndex] == [collectionView.dataSource collectionView:collectionView numberOfItemsInSection:sectionIndex]) {
|
||||
if (sectionIndex < [collectionView numberOfSections]
|
||||
&& sectionIndex < [collectionView.dataSource numberOfSectionsInCollectionView:collectionView]
|
||||
&& [collectionView numberOfItemsInSection:sectionIndex] == [collectionView.dataSource collectionView:collectionView numberOfItemsInSection:sectionIndex]) {
|
||||
// Perfer to do item reloads instead, if the number of items in section is unchanged.
|
||||
[itemUpdates addObjectsFromArray:convertSectionReloadToItemUpdates(localIndexSet, collectionView)];
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in a new issue