From c3ae2906c9bae3ddcfcc4b859d404372ae68a8b3 Mon Sep 17 00:00:00 2001 From: Jiecong Wang Date: Thu, 1 Nov 2018 14:55:49 -0700 Subject: [PATCH] Skip forcing layout when UICollectionView is invisible #trivial (#1268) Summary: Issue fixed: # https://github.com/Instagram/IGListKit/issues/1267 - [ ] All tests pass. Demo project builds and runs. - [ ] I added tests, an experiment, or detailed why my change isn't tested. - [ ] I added an entry to the `CHANGELOG.md` for any breaking changes, enhancements, or bug fixes. - [ ] 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/1268 Reviewed By: maxoll Differential Revision: D12839019 Pulled By: rnystrom fbshipit-source-id: c695d66234d7d1969f9f17f55cbe9d7967970adc --- Source/Common/IGListExperiments.h | 2 ++ Source/IGListAdapterUpdater.m | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Source/Common/IGListExperiments.h b/Source/Common/IGListExperiments.h index 459b7145..30048f33 100644 --- a/Source/Common/IGListExperiments.h +++ b/Source/Common/IGListExperiments.h @@ -24,6 +24,8 @@ typedef NS_OPTIONS (NSInteger, IGListExperiment) { IGListExperimentDeferredToObjectCreation = 1 << 6, /// Test getting collection view at update time. IGListExperimentGetCollectionViewAtUpdate = 1 << 7, + /// Test skipping layout when UICollectionView isn't visible + IGListExperimentSkipLayout = 1 << 8, }; /** diff --git a/Source/IGListAdapterUpdater.m b/Source/IGListAdapterUpdater.m index cfdf92bf..49e69d23 100644 --- a/Source/IGListAdapterUpdater.m +++ b/Source/IGListAdapterUpdater.m @@ -176,7 +176,10 @@ [self _cleanStateAfterUpdates]; [self _performBatchUpdatesItemBlockApplied]; [collectionView reloadData]; - [collectionView layoutIfNeeded]; + if (!IGListExperimentEnabled(self.experiments, IGListExperimentSkipLayout) + || collectionView.window != nil) { + [collectionView layoutIfNeeded]; + } executeCompletionBlocks(YES); };