Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missed delegate call #trivial #1211

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ The changelog for `IGListKit`. Also see the [releases](https://github.com/instag

- Experimental fix to get the `UICollectionView` for batch updating immediately before applying the update. [Ryan Nystrom](https://github.com/rnystrom) (tbd)


- `[IGListAdapterUpdater performBatchUpdatesWithCollectionViewBlock:]` and `[IGListAdapterUpdater performReloadDataWithCollectionViewBlock:]` clean state and run completion blocks if their `UICollectionView` is nil. [Brandon Darin](https://github.com/jbd1030) (tbd)

- 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)

- Log instead of assert for duplicate diff identifiers to make code testable. [Adam Stern](https://github.com/adamastern) (tbd)

3.4.0
Expand Down
1 change: 1 addition & 0 deletions Source/IGListAdapterUpdater.m
Original file line number Diff line number Diff line change
Expand Up @@ -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]];
}
}
Expand Down
40 changes: 40 additions & 0 deletions Tests/IGListAdapterUpdaterTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down