Skip to content

Commit

Permalink
Add missed delegate call #trivial (#1211)
Browse files Browse the repository at this point in the history
Summary:
Issue fixed: #

- [x] All tests pass. Demo project builds and runs.
- [x] I added tests, an experiment, or detailed why my change isn't tested.
- [x] I added an entry to the `CHANGELOG.md` for any breaking changes, enhancements, or bug fixes.
- [x] I have reviewed the [contributing guide](https://github.com/Instagram/IGListKit/blob/master/.github/CONTRIBUTING.md)
Pull Request resolved: #1211

Differential Revision: D9003392

Pulled By: rnystrom

fbshipit-source-id: 73ef837300f8fdb6d9a6005e86f8e9e842827979
  • Loading branch information
bofeizhu authored and facebook-github-bot committed Jul 25, 2018
1 parent f671430 commit 67da3b4
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
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

0 comments on commit 67da3b4

Please sign in to comment.