From af78523453e6362c1ba40ceb326780e8ad069e29 Mon Sep 17 00:00:00 2001 From: Maxime Ollivier Date: Mon, 3 Aug 2020 07:17:41 -0700 Subject: [PATCH] rename movesAsDeletesInserts to sectionMovesAsDeletesInserts Summary: Lets clarify that we're taking about section moves Reviewed By: Haud Differential Revision: D22897102 fbshipit-source-id: ea77ef695ddae8e7b1df96d51002bc8c0cc7fab7 --- Source/IGListKit/IGListAdapterUpdater.h | 20 +++++++++++++------ Source/IGListKit/IGListAdapterUpdater.m | 2 +- .../IGListAdapterUpdater+DebugDescription.m | 2 +- .../Internal/IGListAdapterUpdaterHelpers.h | 2 +- .../Internal/IGListAdapterUpdaterHelpers.m | 4 ++-- Tests/IGListAdapterUpdaterTests.m | 2 +- 6 files changed, 20 insertions(+), 12 deletions(-) diff --git a/Source/IGListKit/IGListAdapterUpdater.h b/Source/IGListKit/IGListAdapterUpdater.h index c7895fa1..185c535c 100644 --- a/Source/IGListKit/IGListAdapterUpdater.h +++ b/Source/IGListKit/IGListAdapterUpdater.h @@ -32,16 +32,21 @@ NS_SWIFT_NAME(ListAdapterUpdater) @property (nonatomic, weak) id delegate; /** - A flag indicating if a move should be treated as a "delete, then insert" operation. + A flag indicating if a section move should be treated as a section "delete, then insert" operation. This can be useful if you're + performing a lot of updates and moves are too distracting. + + Default is NO. */ -@property (nonatomic, assign) BOOL movesAsDeletesInserts; +@property (nonatomic, assign) BOOL sectionMovesAsDeletesInserts; /** ONLY used when there is N section, but each section only contains 1 item. We don't need to change move into delete+insert, and we dont need to call -reload at all. - + This unlocks many default UICollectionView animations: move/inline cell updates/deletes/inserts etc. - + + Default is NO. + @warning This should only work for Section that *ONLY* has single item setup. */ @property (nonatomic, assign) BOOL singleItemSectionUpdates; @@ -50,10 +55,10 @@ NS_SWIFT_NAME(ListAdapterUpdater) A flag indicating that section reloads should be treated as item reloads, instead of converting them to "delete, then insert" operations. This only applies if the number of items for the section is unchanged. + Default is NO. + @note If the number of items for the section is changed, we would fallback to the default behavior and convert it to "delete + insert", because the collectionView can crash otherwise. - - Default is NO. */ @property (nonatomic, assign) BOOL preferItemReloadsForSectionReloads; @@ -61,6 +66,8 @@ NS_SWIFT_NAME(ListAdapterUpdater) A flag indicating whether this updater should skip diffing and simply call `reloadData` for updates when the collection view is not in a window. The default value is `YES`. + Default is YES. + @note This will result in better performance, but will not generate the same delegate callbacks. If using a custom layout, it will not receive `prepareForCollectionViewUpdates:`. @@ -70,6 +77,7 @@ NS_SWIFT_NAME(ListAdapterUpdater) /** If there's more than 100 diff updates, fallback to using `reloadData` to avoid stalling the main thread. + Default is YES. */ @property (nonatomic, assign) BOOL allowsReloadingOnTooManyUpdates; diff --git a/Source/IGListKit/IGListAdapterUpdater.m b/Source/IGListKit/IGListAdapterUpdater.m index b0d96e15..5e8d46cc 100644 --- a/Source/IGListKit/IGListAdapterUpdater.m +++ b/Source/IGListKit/IGListAdapterUpdater.m @@ -227,7 +227,7 @@ typedef void (^IGListAdapterUpdaterCompletionBlock)(BOOL); self.batchUpdates, fromObjects, experiments, - self.movesAsDeletesInserts, + self.sectionMovesAsDeletesInserts, self.preferItemReloadsForSectionReloads); } diff --git a/Source/IGListKit/Internal/IGListAdapterUpdater+DebugDescription.m b/Source/IGListKit/Internal/IGListAdapterUpdater+DebugDescription.m index 44c2a471..99a1678d 100644 --- a/Source/IGListKit/Internal/IGListAdapterUpdater+DebugDescription.m +++ b/Source/IGListKit/Internal/IGListAdapterUpdater+DebugDescription.m @@ -27,7 +27,7 @@ static NSMutableArray *linesFromObjects(NSArray *objects) { - (NSArray *)debugDescriptionLines { NSMutableArray *debug = [NSMutableArray new]; #if defined(IGLK_DEBUG_DESCRIPTION_ENABLED) && IGLK_DEBUG_DESCRIPTION_ENABLED - [debug addObject:[NSString stringWithFormat:@"Moves as deletes+inserts: %@", IGListDebugBOOL(self.movesAsDeletesInserts)]]; + [debug addObject:[NSString stringWithFormat:@"Section moves as deletes+inserts: %@", IGListDebugBOOL(self.sectionMovesAsDeletesInserts)]]; [debug addObject:[NSString stringWithFormat:@"Allows background reloading: %@", IGListDebugBOOL(self.allowsBackgroundReloading)]]; [debug addObject:[NSString stringWithFormat:@"Has queued reload data: %@", IGListDebugBOOL(self.hasQueuedReloadData)]]; [debug addObject:[NSString stringWithFormat:@"Queued update is animated: %@", IGListDebugBOOL(self.queuedUpdateIsAnimated)]]; diff --git a/Source/IGListKit/Internal/IGListAdapterUpdaterHelpers.h b/Source/IGListKit/Internal/IGListAdapterUpdaterHelpers.h index ec4bc6dd..40d0b5e0 100644 --- a/Source/IGListKit/Internal/IGListAdapterUpdaterHelpers.h +++ b/Source/IGListKit/Internal/IGListAdapterUpdaterHelpers.h @@ -27,7 +27,7 @@ IGListBatchUpdateData *IGListApplyUpdatesToCollectionView(UICollectionView *coll IGListBatchUpdates *batchUpdates, NSArray> *fromObjects, IGListExperiment experiments, - BOOL movesAsDeletesInserts, + BOOL sectionMovesAsDeletesInserts, BOOL preferItemReloadsForSectionReloads); NS_ASSUME_NONNULL_END diff --git a/Source/IGListKit/Internal/IGListAdapterUpdaterHelpers.m b/Source/IGListKit/Internal/IGListAdapterUpdaterHelpers.m index 2678e396..dbeb72b7 100644 --- a/Source/IGListKit/Internal/IGListAdapterUpdaterHelpers.m +++ b/Source/IGListKit/Internal/IGListAdapterUpdaterHelpers.m @@ -59,7 +59,7 @@ IGListBatchUpdateData *IGListApplyUpdatesToCollectionView(UICollectionView *coll IGListBatchUpdates *batchUpdates, NSArray> *fromObjects, IGListExperiment experiments, - BOOL movesAsDeletesInserts, + BOOL sectionMovesAsDeletesInserts, BOOL preferItemReloadsForSectionReloads) { NSSet *moves = [[NSSet alloc] initWithArray:diffResult.moves]; @@ -70,7 +70,7 @@ IGListBatchUpdateData *IGListApplyUpdatesToCollectionView(UICollectionView *coll NSMutableIndexSet *inserts = [diffResult.inserts mutableCopy]; NSMutableIndexSet *deletes = [diffResult.deletes mutableCopy]; NSMutableArray *itemUpdates = [NSMutableArray new]; - if (movesAsDeletesInserts) { + if (sectionMovesAsDeletesInserts) { for (IGListMoveIndex *move in moves) { [deletes addIndex:move.from]; [inserts addIndex:move.to]; diff --git a/Tests/IGListAdapterUpdaterTests.m b/Tests/IGListAdapterUpdaterTests.m index 7eb14c01..e042b73e 100644 --- a/Tests/IGListAdapterUpdaterTests.m +++ b/Tests/IGListAdapterUpdaterTests.m @@ -377,7 +377,7 @@ [self.updater performReloadDataWithCollectionViewBlock:[self collectionViewBlock]]; // without moves as inserts, we would assert b/c the # of items in each section changes - self.updater.movesAsDeletesInserts = YES; + self.updater.sectionMovesAsDeletesInserts = YES; XCTestExpectation *expectation = genExpectation; [self.updater performUpdateWithCollectionViewBlock:[self collectionViewBlock] fromObjects:from toObjectsBlock:to animated:YES objectTransitionBlock:self.updateBlock completion:^(BOOL finished) {