IGListKit/Tests/Objects/IGTestBindingSingleItemDataSource.h
Zhisheng Huang b4dc116e20 Add a IGListBindingSingleSectionController
Summary:
= Problem =

Most of the UICollectionView/List UI only needs to deal with 1 dimensional array of data. The current N section N item setup is a big more complicated for most use case who only deals with 1 dimensional array.

In fact, the IGListDiff algorithm works pretty with 1 dimensional array. Then inside `IGListAdapterUpdater`, we do a lot changes to ensure UICollectionVie do not crash:
1. Convert section moves -> delete+insert;
2. Convert section reload -> delete+insert;

This results in the animation limitation for the UI updates, we lose the move animation support by UICollectionView and the updates for delete+insert does not look great.

= Solution =

Hence I am proposing to use simple **Single Item** Section Controller, and we can apply the diffing result directly to the UICollectionView, which is much simpler.

However, for the inline section update, we need to support update at the right timing: inside -didUpdateObject:, and now we want to get back the existing cell, and apply data to it.

Ideally, `IGListSingleSectionController` is the right call but `IGListSingleSectionController` is not subclassable and we would also need to change the way -didUpdateObject: works in that class.

Hence I am building this `IGListBindingSingleSectionController`, which only contains single item, and it can update/bind the cell whenever item is updated.

Reviewed By: iperry90

Differential Revision: D18942974

fbshipit-source-id: 539fbe2b72691b649e3ae3d8ed725006bc54b705
2019-12-16 17:50:50 -08:00

25 lines
653 B
Objective-C

/**
* Copyright (c) Facebook, Inc. and its affiliates.
* 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 <Foundation/Foundation.h>
#import <IGListKit/IGListAdapterDataSource.h>
#import "IGTestObject.h"
#import "IGListTestCase.h"
NS_ASSUME_NONNULL_BEGIN
@interface IGTestBindingSingleItemDataSource : NSObject <IGListTestCaseDataSource>
@property (nonatomic, strong) NSArray<IGTestObject *> *objects;
@end
NS_ASSUME_NONNULL_END