From 26868385c2799d712cac522d5ec300424bf8ccd0 Mon Sep 17 00:00:00 2001 From: Bofei Zhu Date: Mon, 9 Jul 2018 00:43:36 -0400 Subject: [PATCH 1/2] Add missed delegate call --- Source/IGListAdapterUpdater.m | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/IGListAdapterUpdater.m b/Source/IGListAdapterUpdater.m index 19c42afaf..90e8be4ea 100644 --- a/Source/IGListAdapterUpdater.m +++ b/Source/IGListAdapterUpdater.m @@ -534,6 +534,7 @@ - (void)reloadItemInCollectionView:(UICollectionView *)collectionView IGListReloadIndexPath *reload = [[IGListReloadIndexPath alloc] initWithFromIndexPath:fromIndexPath toIndexPath:toIndexPath]; [self.batchUpdates.itemReloads addObject:reload]; } else { + [self.delegate listAdapterUpdater:self willReloadIndexPaths:@[fromIndexPath] collectionView:collectionView]; [collectionView reloadItemsAtIndexPaths:@[fromIndexPath]]; } } From d78a188b89a74560e70e0a31c12171885e141c18 Mon Sep 17 00:00:00 2001 From: Bofei Zhu Date: Tue, 17 Jul 2018 17:05:09 -0400 Subject: [PATCH 2/2] Update CHANGELOG.md and add unit test --- CHANGELOG.md | 2 ++ Tests/IGListAdapterUpdaterTests.m | 40 +++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb2e994fe..fc743932d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,8 @@ The changelog for `IGListKit`. Also see the [releases](https://github.com/instag - Ensuring view models with duplicate diff identifiers are removed when view models are first requested by `IGListBindingSectionController` [Adam Stern](https://github.com/adamastern) (tbd) +- Fixed `[IGListAdapterUpdater reloadItemInCollectionView:fromIndexPath:toIndexPath:]` does not call delegate when not inside a batch update. [Bofei Zhu] (https://github.com/zhubofei) [(#1211)](https://github.com/Instagram/IGListKit/pull/1211) + 3.4.0 ----- diff --git a/Tests/IGListAdapterUpdaterTests.m b/Tests/IGListAdapterUpdaterTests.m index b32659e84..3e4c476d0 100644 --- a/Tests/IGListAdapterUpdaterTests.m +++ b/Tests/IGListAdapterUpdaterTests.m @@ -602,6 +602,46 @@ - (void)test_whenNotInViewHierarchy_thatUpdatesStillExecuteBlocks { [self waitForExpectationsWithTimeout:30 handler:nil]; } +- (void)test_whenNotBatchUpdate_thatDelegateEventsSent { + IGSectionObject *object = [IGSectionObject sectionWithObjects:@[@0, @1, @2]]; + self.dataSource.sections = @[object]; + [self.collectionView reloadData]; + + id mockDelegate = [OCMockObject niceMockForProtocol:@protocol(IGListAdapterUpdaterDelegate)]; + self.updater.delegate = mockDelegate; + [mockDelegate setExpectationOrderMatters:YES]; + [[mockDelegate expect] listAdapterUpdater:self.updater willDeleteIndexPaths:OCMOCK_ANY collectionView:self.collectionView]; + [[mockDelegate expect] listAdapterUpdater:self.updater willInsertIndexPaths:OCMOCK_ANY collectionView:self.collectionView]; + [[mockDelegate expect] listAdapterUpdater:self.updater + willMoveFromIndexPath:OCMOCK_ANY + toIndexPath:OCMOCK_ANY + collectionView:self.collectionView]; + [[mockDelegate expect] listAdapterUpdater:self.updater willReloadIndexPaths:OCMOCK_ANY collectionView:self.collectionView]; + + // This code is of no use, but it will let UICollectionView synchronize number of items, + // so it will not crash in following updates. https://stackoverflow.com/a/46751421/2977647 + [self.collectionView numberOfItemsInSection:0]; + + object.objects = @[@1, @2]; + [self.updater deleteItemsFromCollectionView:self.collectionView indexPaths:@[ + [NSIndexPath indexPathForItem:0 inSection:0], + ]]; + object.objects = @[@1, @2, @4, @5]; + [self.updater insertItemsIntoCollectionView:self.collectionView indexPaths:@[ + [NSIndexPath indexPathForItem:2 inSection:0], + [NSIndexPath indexPathForItem:3 inSection:0], + ]]; + object.objects = @[@2, @1, @4, @5]; + [self.updater moveItemInCollectionView:self.collectionView + fromIndexPath:[NSIndexPath indexPathForItem:2 inSection:0] + toIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]]; + + [self.updater reloadItemInCollectionView:self.collectionView + fromIndexPath:[NSIndexPath indexPathForItem:0 inSection:0] + toIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]]; + [mockDelegate verify]; +} + - (void)test_whenObjectIdentifiersCollide_withDifferentTypes_thatLookupReturnsNil { id testObject = [[IGTestObject alloc] initWithKey:@"foo" value:@"bar"]; id collision = @"foo";