IGListKit/Tests/Objects/IGListTestUICollectionViewDataSource.h
Zhisheng Huang f699ea0e17 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-28 23:32:43 -07:00

30 lines
871 B
Objective-C

/**
* Copyright (c) 2016-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#import <UIKit/UIKit.h>
#import <IGListKit/IGListDiffable.h>
@interface IGSectionObject : NSObject <IGListDiffable>
@property (nonatomic, strong) NSArray *objects;
+ (instancetype)sectionWithObjects:(NSArray *)objects;
+ (instancetype)sectionWithObjects:(NSArray *)objects identifier:(NSString *)identifier;
@end
@interface IGListTestUICollectionViewDataSource : NSObject <UICollectionViewDataSource>
@property (nonatomic, strong) NSArray <IGSectionObject *> *sections;
- (instancetype)initWithCollectionView:(UICollectionView *)collectionView;
@end