Skip to content

Commit

Permalink
ship IGListExperimentUseCollectionViewInsteadOfDataSourceInLayout
Browse files Browse the repository at this point in the history
Summary: Ship this experiment. `IGListCollectionViewLayout` should get the section/index counts via `UICollectionView` to stay in sync, instead of the `dataSource`.

Reviewed By: apadalko

Differential Revision: D21789871

fbshipit-source-id: 9fe069bd793b36680cd8562e69c7367d69a11ec7
  • Loading branch information
maxolls authored and facebook-github-bot committed May 29, 2020
1 parent 9fcc122 commit 677ce77
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ The changelog for `IGListKit`. Also see the [releases](https://github.com/instag

- Added `APPLICATION_EXTENSION_API_ONLY` support for `IGListDiffKit` [Peter Meyers](https://github.com/pm-dev) [(#1422)](https://github.com/Instagram/IGListKit/pull/1422)

### Fixes

- `IGListCollectionViewLayout` should get the section/index counts via `UICollectionView` to stay in sync, instead of the `dataSource` [Maxime Ollivier](https://github.com/maxolls) (tbd)

4.0.0
-----
### Breaking Changes
Expand Down
2 changes: 0 additions & 2 deletions Source/IGListDiffKit/IGListExperiments.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ typedef NS_OPTIONS (NSInteger, IGListExperiment) {
IGListExperimentGetCollectionViewAtUpdate = 1 << 7,
/// Test invalidating layout when cell reloads/updates in IGListBindingSectionController.
IGListExperimentInvalidateLayoutForUpdates = 1 << 8,
/// Test using the collection view when asking for layout instead of accessing the data source. Only apply to IGListCollectionViewLayout.
IGListExperimentUseCollectionViewInsteadOfDataSourceInLayout = 1 << 9
};

/**
Expand Down
9 changes: 2 additions & 7 deletions Source/IGListKit/IGListCollectionViewLayout.mm
Original file line number Diff line number Diff line change
Expand Up @@ -465,12 +465,9 @@ - (void)_calculateLayoutIfNeeded {
[self _resetSupplementaryAttributesCache];

UICollectionView *collectionView = self.collectionView;
id<UICollectionViewDataSource> dataSource = collectionView.dataSource;
id<UICollectionViewDelegateFlowLayout> delegate = (id<UICollectionViewDelegateFlowLayout>)collectionView.delegate;

const NSInteger sectionCount = (IGListExperimentEnabled(_experiments, IGListExperimentUseCollectionViewInsteadOfDataSourceInLayout)
? [collectionView numberOfSections]
: [dataSource numberOfSectionsInCollectionView:collectionView]);
const NSInteger sectionCount = [collectionView numberOfSections];
const UIEdgeInsets contentInset = collectionView.ig_contentInset;
const CGRect contentInsetAdjustedCollectionViewBounds = UIEdgeInsetsInsetRect(collectionView.bounds, contentInset);

Expand All @@ -493,9 +490,7 @@ - (void)_calculateLayoutIfNeeded {
}

for (NSInteger section = _minimumInvalidatedSection; section < sectionCount; section++) {
const NSInteger itemCount = (IGListExperimentEnabled(_experiments, IGListExperimentUseCollectionViewInsteadOfDataSourceInLayout)
? [collectionView numberOfItemsInSection:section]
: [dataSource collectionView:collectionView numberOfItemsInSection:section]);
const NSInteger itemCount = [collectionView numberOfItemsInSection:section];
const BOOL itemsEmpty = itemCount == 0;
const BOOL hideHeaderWhenItemsEmpty = itemsEmpty && !self.showHeaderWhenEmpty;
_sectionData[section].itemBounds = std::vector<CGRect>(itemCount);
Expand Down

0 comments on commit 677ce77

Please sign in to comment.