IGListBindingSectionController no longer asserts when reloading the entire section. (#1213)

Summary:
Issue fixed: #1174

- [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: https://github.com/Instagram/IGListKit/pull/1213

Differential Revision: D9003398

Pulled By: rnystrom

fbshipit-source-id: 2c68f42e21abaea9191f26309668d866544f80b4
This commit is contained in:
Jeff Bailey 2018-07-25 14:31:05 -07:00 committed by Facebook Github Bot
parent 67da3b4f5f
commit a7d720d007
3 changed files with 20 additions and 5 deletions

View file

@ -12,6 +12,8 @@ The changelog for `IGListKit`. Also see the [releases](https://github.com/instag
- Added `IGListCollectionScrollingTraits` for exposing `UICollectionView` scrolling traits to section controllers via `IGListCollectionContext`. [Adam Stern](https://github.com/adamastern) (tbd)
- `IGListBindingSectionController` no longer asserts when reloading the entire section. A warning message is now logged if the entire section is going to be reloaded. [Jeff Bailey](https://github.com/jeffbailey) (#1213)
### Fixes
- Experimental fix to get the `UICollectionView` for batch updating immediately before applying the update. [Ryan Nystrom](https://github.com/rnystrom) (tbd)

View file

@ -115,9 +115,12 @@ typedef NS_ENUM(NSInteger, IGListDiffingSectionState) {
NSArray *viewModels = [self.dataSource sectionController:self viewModelsForObject:object];
self.viewModels = objectsWithDuplicateIdentifiersRemoved(viewModels);
} else {
IGAssert([oldObject isEqualToDiffableObject:object],
@"Unequal objects %@ and %@ will cause IGListBindingSectionController to reload the entire section",
oldObject, object);
#if IGLK_LOGGING_ENABLED
if (![oldObject isEqualToDiffableObject:object]) {
IGLKLog(@"Warning: Unequal objects %@ and %@ will cause IGListBindingSectionController to reload the entire section",
oldObject, object);
}
#endif
[self updateAnimated:YES completion:nil];
}
}

View file

@ -28,8 +28,18 @@
return self.key;
}
- (BOOL)isEqualToDiffableObject:(id<IGListDiffable>)object {
return YES;
- (BOOL)isEqualToDiffableObject:(id)object {
if (object == self) {
return YES;
}
if ([object isKindOfClass:[IGTestDiffingObject class]]) {
/* A simple equality test that only looks at the number of objects for the key.
It does not currently test the equality of each of the objects. */
IGTestDiffingObject *testDiffingObject = (IGTestDiffingObject *)object;
return self.objects.count == testDiffingObject.objects.count;
}
return NO;
}
@end