From 34c935c1a5fee83283beece8f1c6b3d6344f275d Mon Sep 17 00:00:00 2001 From: Maxime Ollivier Date: Fri, 26 Jun 2020 10:03:47 -0700 Subject: [PATCH] clean up IGListExperimentGetCollectionViewAtUpdate Summary: Experiment shipped. Reviewed By: Haud, lorixx Differential Revision: D22219242 fbshipit-source-id: 60dbb5f008656ae67b02294ef16138703ebe392f --- CHANGELOG.md | 2 ++ Source/IGListDiffKit/IGListExperiments.h | 4 +--- Source/IGListKit/IGListAdapter.m | 12 +++--------- Tests/IGListAdapterE2ETests.m | 4 ---- 4 files changed, 6 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8da30863b..c270140ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,8 @@ The changelog for `IGListKit`. Also see the [releases](https://github.com/instag - Fixed missing update when calling `performUpdatesAnimated` multiple times quickly and using the `reloadDataFallback()`. [Maxime Ollivier](https://github.com/maxolls) (tbd) +- Request the `UICollectionView` until just-before we update. This way if the `UICollectionView` is changed between update-queue and execution, we guarantee the update is performed on the correct view. Ship with experiment `IGListExperimentGetCollectionViewAtUpdate` from Ryan Nystrom. [Maxime Ollivier](https://github.com/maxolls) (tbd) + 4.0.0 ----- ### Breaking Changes diff --git a/Source/IGListDiffKit/IGListExperiments.h b/Source/IGListDiffKit/IGListExperiments.h index 852150c8e..77d7f2824 100644 --- a/Source/IGListDiffKit/IGListExperiments.h +++ b/Source/IGListDiffKit/IGListExperiments.h @@ -22,10 +22,8 @@ typedef NS_OPTIONS (NSInteger, IGListExperiment) { IGListExperimentReloadDataFallback = 1 << 3, /// Test deferring object creation until just before diffing. IGListExperimentDeferredToObjectCreation = 1 << 4, - /// Test getting collection view at update time. - IGListExperimentGetCollectionViewAtUpdate = 1 << 5, /// Test invalidating layout when cell reloads/updates in IGListBindingSectionController. - IGListExperimentInvalidateLayoutForUpdates = 1 << 6, + IGListExperimentInvalidateLayoutForUpdates = 1 << 5, }; /** diff --git a/Source/IGListKit/IGListAdapter.m b/Source/IGListKit/IGListAdapter.m index 645c844f0..8f61d6169 100644 --- a/Source/IGListKit/IGListAdapter.m +++ b/Source/IGListKit/IGListAdapter.m @@ -107,8 +107,7 @@ - (void)setCollectionView:(UICollectionView *)collectionView { [self _updateCollectionViewDelegate]; // only construct - if (!IGListExperimentEnabled(self.experiments, IGListExperimentGetCollectionViewAtUpdate) - || settingFirstCollectionView) { + if (settingFirstCollectionView) { [self _updateAfterPublicSettingsChange]; } } @@ -573,13 +572,8 @@ - (CGSize)sizeForSupplementaryViewOfKind:(NSString *)elementKind atIndexPath:(NS #pragma mark - Private API - (IGListCollectionViewBlock)_collectionViewBlock { - if (IGListExperimentEnabled(self.experiments, IGListExperimentGetCollectionViewAtUpdate)) { - __weak __typeof__(self) weakSelf = self; - return ^UICollectionView *{ return weakSelf.collectionView; }; - } else { - __weak UICollectionView *collectionView = _collectionView; - return ^UICollectionView *{ return collectionView; }; - } + __weak __typeof__(self) weakSelf = self; + return ^UICollectionView *{ return weakSelf.collectionView; }; } // this method is what updates the "source of truth" diff --git a/Tests/IGListAdapterE2ETests.m b/Tests/IGListAdapterE2ETests.m index 4d39044f1..d98a5ae7f 100644 --- a/Tests/IGListAdapterE2ETests.m +++ b/Tests/IGListAdapterE2ETests.m @@ -1841,7 +1841,6 @@ - (void)test_whenModifyingInitialAndFinalAttribute_thatLayoutIsCorrect { - (void)test_whenSwappingCollectionViewsAfterUpdate_thatUpdatePerformedOnTheCorrectCollectionView { // BEGIN: setup of FIRST adapter+dataSource+collectionView IGListAdapter *adapter1 = [[IGListAdapter alloc] initWithUpdater:[IGListAdapterUpdater new] viewController:nil]; - adapter1.experiments |= IGListExperimentGetCollectionViewAtUpdate; UICollectionView *collectionView1 = [[UICollectionView alloc] initWithFrame:self.window.frame collectionViewLayout:[UICollectionViewFlowLayout new]]; [self.window addSubview:collectionView1]; @@ -1857,7 +1856,6 @@ - (void)test_whenSwappingCollectionViewsAfterUpdate_thatUpdatePerformedOnTheCorr // BEGIN: setup of SECOND adapter+dataSource+collectionView IGListAdapter *adapter2 = [[IGListAdapter alloc] initWithUpdater:[IGListAdapterUpdater new] viewController:nil]; - adapter2.experiments |= IGListExperimentGetCollectionViewAtUpdate; UICollectionView *collectionView2 = [[UICollectionView alloc] initWithFrame:self.window.frame collectionViewLayout:[UICollectionViewFlowLayout new]]; [self.window addSubview:collectionView2]; @@ -1891,7 +1889,6 @@ - (void)test_whenCollectionViewBecomesNilDuringPerformUpdates_thatStateCleanedCo [self setupWithObjects:@[ genTestObject(@1, @1) ]]; - self.adapter.experiments |= IGListExperimentGetCollectionViewAtUpdate; // perform update on listAdapter XCTestExpectation *expectation1 = genExpectation; @@ -1938,7 +1935,6 @@ - (void)test_whenCollectionViewBecomesNilDuringReloadData_thatStateCleanedCorrec [self setupWithObjects:@[ genTestObject(@1, @1) ]]; - self.adapter.experiments |= IGListExperimentGetCollectionViewAtUpdate; // reload data on listAdapter XCTestExpectation *expectation1 = genExpectation;