IGListKit/Source/Internal/UICollectionView+IGListBatchUpdateData.m
Zhisheng Huang 6cdd112790 Fix some crash from IGListKit that nil dataSource might result in crash
Summary:
This happens when we set collectionView.dataSource to be nil before calling performUpdates:, the crash is easily reproduced by a simple unit test.

To make the infra more robust and we don't crash the app, let's add an early return before applying a collectionView update.

Reviewed By: rnystrom, calimarkus

Differential Revision: D12896196

fbshipit-source-id: ab024d0e7e9282d50c3be297e1e67cfccaff8242
2018-11-06 11:37:27 -08:00

31 lines
990 B
Objective-C

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "UICollectionView+IGListBatchUpdateData.h"
#import <IGListKit/IGListBatchUpdateData.h>
@implementation UICollectionView (IGListBatchUpdateData)
- (void)ig_applyBatchUpdateData:(IGListBatchUpdateData *)updateData {
[self deleteItemsAtIndexPaths:updateData.deleteIndexPaths];
[self insertItemsAtIndexPaths:updateData.insertIndexPaths];
[self reloadItemsAtIndexPaths:updateData.updateIndexPaths];
for (IGListMoveIndexPath *move in updateData.moveIndexPaths) {
[self moveItemAtIndexPath:move.from toIndexPath:move.to];
}
for (IGListMoveIndex *move in updateData.moveSections) {
[self moveSection:move.from toSection:move.to];
}
[self deleteSections:updateData.deleteSections];
[self insertSections:updateData.insertSections];
}
@end