mirror of
https://github.com/Instagram/IGListKit
synced 2026-05-24 09:48:21 +00:00
Balance reload delete and insert calls
Summary:
In 073fc073e0 we deduped delete calls, but since we convert reloads into delete+insert when only deduping deletes, we end up with unbalanced delete+insert calls.
Unit test added reproduced a crash we see internally. Fix passes the test.
Not adding a changelog entry since this is a new regression fixed between releases. #trivial
Issue fixed: t17539856
- [x] All tests pass. Demo project builds and runs.
- [x] I added tests, an experiment, or detailed why my change isn't tested.
Closes https://github.com/Instagram/IGListKit/pull/687
Differential Revision: D4933545
Pulled By: rnystrom
fbshipit-source-id: d38a900a99b1aa796dd654ddedb42e3cb4ef4378
This commit is contained in:
parent
5fe27d8809
commit
ee4f3c95c6
2 changed files with 25 additions and 2 deletions
|
|
@ -280,12 +280,16 @@ void convertReloadToDeleteInsert(NSMutableIndexSet *reloads,
|
|||
NSMutableArray<IGListMoveIndexPath *> *itemMoves = batchUpdates.itemMoves;
|
||||
|
||||
NSSet<NSIndexPath *> *uniqueDeletes = [NSSet setWithArray:itemDeletes];
|
||||
NSMutableSet<NSIndexPath *> *reloadDeletePaths = [NSMutableSet new];
|
||||
NSMutableSet<NSIndexPath *> *reloadInsertPaths = [NSMutableSet new];
|
||||
for (IGListReloadIndexPath *reload in batchUpdates.itemReloads) {
|
||||
if (![uniqueDeletes containsObject:reload.fromIndexPath]) {
|
||||
[itemDeletes addObject:reload.fromIndexPath];
|
||||
[itemInserts addObject:reload.toIndexPath];
|
||||
[reloadDeletePaths addObject:reload.fromIndexPath];
|
||||
[reloadInsertPaths addObject:reload.toIndexPath];
|
||||
}
|
||||
}
|
||||
[itemDeletes addObjectsFromArray:[reloadDeletePaths allObjects]];
|
||||
[itemInserts addObjectsFromArray:[reloadInsertPaths allObjects]];
|
||||
|
||||
IGListBatchUpdateData *updateData = [[IGListBatchUpdateData alloc] initWithInsertSections:inserts
|
||||
deleteSections:deletes
|
||||
|
|
|
|||
|
|
@ -1460,5 +1460,24 @@
|
|||
[self waitForExpectationsWithTimeout:30 handler:nil];
|
||||
}
|
||||
|
||||
- (void)test_whenReloadingSameItemTwice_thatDeletesAndInsertsAreBalanced {
|
||||
[self setupWithObjects:@[
|
||||
genTestObject(@1, @4),
|
||||
]];
|
||||
|
||||
IGTestObject *object = self.dataSource.objects[0];
|
||||
IGListSectionController *sectionController = [self.adapter sectionControllerForObject:object];
|
||||
|
||||
XCTestExpectation *expectation = genExpectation;
|
||||
[sectionController.collectionContext performBatchAnimated:YES updates:^(id<IGListBatchContext> batchContext) {
|
||||
[batchContext reloadInSectionController:sectionController atIndexes:[NSIndexSet indexSetWithIndex:0]];
|
||||
[batchContext reloadInSectionController:sectionController atIndexes:[NSIndexSet indexSetWithIndex:0]];
|
||||
} completion:^(BOOL finished2) {
|
||||
XCTAssertEqual([self.collectionView numberOfSections], 1);
|
||||
XCTAssertEqual([self.collectionView numberOfItemsInSection:0], 4);
|
||||
[expectation fulfill];
|
||||
}];
|
||||
[self waitForExpectationsWithTimeout:30 handler:nil];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
|||
Loading…
Reference in a new issue