From fb9d8cea8e5b992805f89cb09093a58c0c8fbac4 Mon Sep 17 00:00:00 2001 From: Sven Bacia Date: Tue, 13 Dec 2016 07:08:12 -0800 Subject: [PATCH] disables prefetchEnabled by default Summary: Disables `prefetchEnabled` by default on `IGListCollectionView` (#318). - [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 have reviewed the [contributing guide](https://github.com/Instagram/IGListKit/blob/master/.github/CONTRIBUTING.md) Closes https://github.com/Instagram/IGListKit/pull/323 Differential Revision: D4319761 Pulled By: rnystrom fbshipit-source-id: a3ea4c3d1d1f3123a60c8168fb333e73ab93cb1e --- CHANGELOG.md | 3 +++ Source/IGListCollectionView.m | 13 +++++++++++++ Tests/IGListCollectionViewTests.m | 18 ++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d551274..fae013ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ The changelog for `IGListKit`. Also see the [releases](https://github.com/instag This release closes the [2.1.0 milestone](https://github.com/Instagram/IGListKit/milestone/2). +### Enhancements +- Disables `prefetchEnabled` by default on `IGListCollectionView`. [Sven Bacia (#323)](https://github.com/Instagram/IGListKit/pull/323) + 2.0.0 ----- diff --git a/Source/IGListCollectionView.m b/Source/IGListCollectionView.m index feace35a..c167b61e 100644 --- a/Source/IGListCollectionView.m +++ b/Source/IGListCollectionView.m @@ -19,11 +19,24 @@ self.backgroundColor = [UIColor whiteColor]; } + if ([self respondsToSelector:@selector(setPrefetchingEnabled:)]) { + self.prefetchingEnabled = NO; + } + self.alwaysBounceVertical = YES; } return self; } +- (instancetype)initWithCoder:(NSCoder *)aDecoder { + if (self = [super initWithCoder:aDecoder]) { + if ([self respondsToSelector:@selector(setPrefetchingEnabled:)]) { + self.prefetchingEnabled = NO; + } + } + return self; +} + - (void)layoutSubviews { /** UICollectionView will sometimes lay its cells out with an animation. This is especially noticeable on older devices diff --git a/Tests/IGListCollectionViewTests.m b/Tests/IGListCollectionViewTests.m index ed9446bd..785a5dc2 100644 --- a/Tests/IGListCollectionViewTests.m +++ b/Tests/IGListCollectionViewTests.m @@ -50,6 +50,24 @@ static const CGRect kIGListCollectionViewTestFrame = (CGRect){{0.0, 0.0}, {100.0 IGListCollectionView *collectionView = [[IGListCollectionView alloc] initWithFrame: kIGListCollectionViewTestFrame collectionViewLayout:[UICollectionViewFlowLayout new]]; XCTAssertTrue(collectionView.alwaysBounceVertical); + + if ([collectionView respondsToSelector:@selector(isPrefetchingEnabled)]) { + XCTAssertFalse(collectionView.isPrefetchingEnabled); + } +} + +-(void)test_thatStoryboardIGListCollectionViewHasCorrectDefaults { + UIWindow *window = [[UIWindow alloc] initWithFrame:kIGListCollectionViewTestFrame]; + UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"IGTestStoryboard" bundle:[NSBundle bundleForClass:self.class]]; + IGTestStoryboardViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"testVC"]; + [window addSubview:viewController.view]; + [viewController performSelectorOnMainThread:@selector(loadView) withObject:nil waitUntilDone:YES]; + + XCTAssertFalse(viewController.collectionView.alwaysBounceVertical); + + if ([UICollectionView instancesRespondToSelector:@selector(isPrefetchingEnabled)]) { + XCTAssertFalse(viewController.collectionView.isPrefetchingEnabled); + } } -(void)test_whenUsingUIAppearance_thatStoryboardIGListCollectionViewUsesAppearanceBackgroundColor {