2019-12-19 17:32:49 +00:00
|
|
|
/*
|
2023-04-06 09:44:16 +00:00
|
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
2016-09-07 22:37:59 +00:00
|
|
|
*
|
2019-12-19 17:32:49 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2016-09-07 22:37:59 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#import <UIKit/UIKit.h>
|
|
|
|
|
|
2019-10-31 15:17:38 +00:00
|
|
|
#import <IGListDiffKit/IGListDiffable.h>
|
2016-09-07 22:37:59 +00:00
|
|
|
|
|
|
|
|
@interface IGSectionObject : NSObject <IGListDiffable>
|
|
|
|
|
|
2019-12-19 17:32:49 +00:00
|
|
|
@property (nonatomic, copy) NSArray *objects;
|
2016-09-07 22:37:59 +00:00
|
|
|
|
|
|
|
|
+ (instancetype)sectionWithObjects:(NSArray *)objects;
|
|
|
|
|
|
Add option to update cells instead of delete+insert for section reload
Summary:
We have seen unnecessary flashiness updates for any section reload updates.
Basically we have 1 section for 1 cell, which is recommended by the IGListKit document in https://instagram.github.io/IGListKit/best-practices-and-faq.html, specifically:
> "We highly recommend using single-item sections when possible."
However, the issue is that whenever we update the underlying data model, we would trigger a delete+insert for the section reload.
In order to mitigate that, we can fix this delete+insert changes or we use the `IGListBindingSectionController`, however, the latter one requires more refactoring plus view model wrapper to have `isEqualToDifferable:` to return YES, which seems less than ideal.
I am proposing that we add an option to the `IGListAdapterUpdater`, as `preferItemReloadsForSectionReloads` so that when it's set to YES, we would trigger the proper `-[UICollectionView reloadItemsAtIndexPaths:]` which handles the cell update properly.
This option also handles the case where the number of items in the section is changed before and after the updates, in that case, it will fallback to do the "delete+insert" section operation.
Reviewed By: rnystrom
Differential Revision: D9519519
fbshipit-source-id: 22ecca07679ebdd212cf771c61e40887cb6a9ba8
2018-08-29 06:22:13 +00:00
|
|
|
+ (instancetype)sectionWithObjects:(NSArray *)objects identifier:(NSString *)identifier;
|
|
|
|
|
|
2019-12-04 23:30:33 +00:00
|
|
|
/**
|
|
|
|
|
@param usesIdentifierForDiffable YES if we only use the `identifier` for -isEqualToDiffableObject. NO then we compares both the `identifier` as well as `objects`.
|
|
|
|
|
*/
|
|
|
|
|
+ (instancetype)sectionWithObjects:(NSArray *)objects identifier:(NSString *)identifier usesIdentifierForDiffable:(BOOL)usesIdentifierForDiffable;
|
|
|
|
|
|
2016-09-07 22:37:59 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@interface IGListTestUICollectionViewDataSource : NSObject <UICollectionViewDataSource>
|
|
|
|
|
|
2019-12-19 17:32:49 +00:00
|
|
|
@property (nonatomic, copy) NSArray <IGSectionObject *> *sections;
|
2016-09-07 22:37:59 +00:00
|
|
|
|
|
|
|
|
- (instancetype)initWithCollectionView:(UICollectionView *)collectionView;
|
|
|
|
|
|
|
|
|
|
@end
|