Disable prefetching when setting the collection view

Summary:
Followup from #852 since `UIAppearance` doesn't have any effect. Automatically disable prefetching.

Issue fixed: #846

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

Reviewed By: jeremycohen

Differential Revision: D5651413

Pulled By: rnystrom

fbshipit-source-id: ed602aa4609038bd629c9366c383a23f32fc88df
This commit is contained in:
Ryan Nystrom 2017-08-21 07:13:55 -07:00 committed by Facebook Github Bot
parent ae3604c3fe
commit 5ca167806b
4 changed files with 22 additions and 0 deletions

View file

@ -12,17 +12,22 @@ The changelog for `IGListKit`. Also see the [releases](https://github.com/instag
### Fixes
- Prevent a crash when update queued immediately after item batch update. [Ryan Nystrom](https://github.com/rnystrom) (tbd)
- Return correct `-[IGListAdapter visibleSectionControllers]` when section has no items, but has supplementary views. [Mani Ghasemlou](https://github.com/manicakes) [(#643)](https://github.com/Instagram/IGListKit/issues/643)
- Call `[CATransaction commit]` before calling completion block in IGListAdapterUpdater to prevent animation issues. [Maxime Ollivier](https://github.com/maxoll) (tbd)
- Fix `scrollToObject:supplementaryKinds:...` not scrolling when section is empty but does have supplymentary views
### Enhancements
- Added `-[IGListSectionController didDeselectItemAtIndex:]` API to support default `UICollectionView` cell deselection. [Ryan Nystrom](https://github.com/rnystrom) (tbd)
- Added `-[IGListCollectionContext selectItemAtIndex:]` Select an item through IGListCollectionContext like `-[IGListCollectionContext deselectItemAtIndex:]`. [Marvin Nazari](https://github.com/MarvinNazari) (tbd)
- Added horizontal scrolling support to `IGListCollectionViewLayout`. [Peter Edmonston](https://github.com/edmonston) [(#857)](https://github.com/Instagram/IGListKit/pull/857)
- Automatically disable `[UICollectionView isPrefetchingEnabled]` when setting a collection view on an adapter. [Ryan Nystrom](https://github.com/rnystrom) [(#889)](https://github.com/Instagram/IGListKit/pull/889)
3.0.0
-----

View file

@ -49,6 +49,8 @@ NS_SWIFT_NAME(ListAdapter)
/**
The collection view used with the adapter.
@note Setting this property will automatically set isPrefetchingEnabled to `NO` for performance reasons.
*/
@property (nonatomic, nullable, weak) UICollectionView *collectionView;

View file

@ -96,6 +96,11 @@
_collectionView = collectionView;
_collectionView.dataSource = self;
if ([_collectionView respondsToSelector:@selector(setPrefetchingEnabled:)]) {
_collectionView.prefetchingEnabled = NO;
}
[_collectionView.collectionViewLayout invalidateLayout];
[self updateCollectionViewDelegate];

View file

@ -1356,4 +1356,14 @@
XCTAssertThrows([self.adapter reloadDataWithCompletion:nil]);
}
- (void)test_whenPrefetchingEnabled_thatSetterDisables {
UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:[UICollectionViewFlowLayout new]];
collectionView.prefetchingEnabled = YES;
IGListAdapter *adapter = [[IGListAdapter alloc] initWithUpdater:[IGListAdapterUpdater new] viewController:nil];
adapter.collectionView = collectionView;
XCTAssertFalse(collectionView.prefetchingEnabled);
}
@end