Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit 6945555

Browse files
committed
Sort in ascending order before removing nodes and restore FIXME
1 parent 6566b7a commit 6945555

1 file changed

Lines changed: 4 additions & 8 deletions

File tree

AsyncDisplayKit/Details/ASDataController.mm

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -816,9 +816,8 @@ - (void)deleteRowsAtIndexPaths:(NSArray *)indexPaths withAnimationOptions:(ASDat
816816
[_editingTransactionQueue waitUntilAllOperationsAreFinished];
817817

818818
// Sort indexPath in order to avoid messing up the index when deleting in several batches.
819-
// When you delete at an index, you invalidate all subsequent indices, and we never want to use an invalid index
820-
// in a later delete so we should have the sorted index path's array in descendent order
821-
NSArray *sortedIndexPaths = [indexPaths sortedArrayUsingSelector:@selector(asdk_inverseCompare:)];
819+
// FIXME: Shouldn't deletes be sorted in descending order?
820+
NSArray *sortedIndexPaths = [indexPaths sortedArrayUsingSelector:@selector(compare:)];
822821

823822
[_editingTransactionQueue addOperationWithBlock:^{
824823
LOG(@"Edit Transaction - deleteRows: %@", indexPaths);
@@ -840,6 +839,7 @@ - (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withAnimationOptions:(ASDat
840839
NSMutableArray<ASIndexedNodeContext *> *contexts = [[NSMutableArray alloc] initWithCapacity:indexPaths.count];
841840

842841
// Sort indexPath to avoid messing up the index when deleting
842+
// FIXME: Shouldn't deletes be sorted in descending order?
843843
NSArray *sortedIndexPaths = [indexPaths sortedArrayUsingSelector:@selector(compare:)];
844844

845845
id<ASEnvironment> environment = [self.environmentDelegate dataControllerEnvironment];
@@ -854,13 +854,9 @@ - (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withAnimationOptions:(ASDat
854854
environmentTraitCollection:environmentTraitCollection]];
855855
}
856856

857-
// When you delete at an index, you invalidate all subsequent indices, and we never want to use an invalid
858-
// index in a later delete so we should have the sorted index path's array in descendent order
859-
NSArray *reverseSortedIndexPaths = [[sortedIndexPaths reverseObjectEnumerator] allObjects];
860-
861857
[_editingTransactionQueue addOperationWithBlock:^{
862858
LOG(@"Edit Transaction - reloadRows: %@", indexPaths);
863-
[self _deleteNodesAtIndexPaths:reverseSortedIndexPaths withAnimationOptions:animationOptions];
859+
[self _deleteNodesAtIndexPaths:sortedIndexPaths withAnimationOptions:animationOptions];
864860
[self _batchLayoutNodesFromContexts:contexts withAnimationOptions:animationOptions];
865861
}];
866862
}];

0 commit comments

Comments
 (0)