Skip to content

Commit 06e18a1

Browse files
committed
Fix collection cell editing bug for iOS 9 & 10
1 parent a63d438 commit 06e18a1

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

Source/ASCollectionView.mm

+28-3
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,12 @@ @interface ASCollectionView () <ASRangeControllerDataSource, ASRangeControllerDe
147147
* (0 sections) we always check at least once after each update (initial reload is the first update.)
148148
*/
149149
BOOL _hasEverCheckedForBatchFetchingDueToUpdate;
150+
151+
/**
152+
* Set during beginInteractiveMovementForItemAtIndexPath and UIGestureRecognizerStateEnded
153+
* (or UIGestureRecognizerStateFailed, UIGestureRecognizerStateCancelled.
154+
*/
155+
BOOL _editting;
150156

151157
/**
152158
* Counter used to keep track of nested batch updates.
@@ -1021,9 +1027,28 @@ - (void)reloadItemsAtIndexPaths:(NSArray *)indexPaths
10211027
- (void)moveItemAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath
10221028
{
10231029
ASDisplayNodeAssertMainThread();
1024-
[self performBatchUpdates:^{
1025-
[_changeSet moveItemAtIndexPath:indexPath toIndexPath:newIndexPath animationOptions:kASCollectionViewAnimationNone];
1026-
} completion:nil];
1030+
if (!_editting) {
1031+
[self performBatchUpdates:^{
1032+
[_changeSet moveItemAtIndexPath:indexPath toIndexPath:newIndexPath animationOptions:kASCollectionViewAnimationNone];
1033+
} completion:nil];
1034+
} else {
1035+
[super moveItemAtIndexPath:indexPath toIndexPath:newIndexPath];
1036+
}
1037+
}
1038+
1039+
- (BOOL)beginInteractiveMovementForItemAtIndexPath:(NSIndexPath *)indexPath {
1040+
_editting = YES;
1041+
return [super beginInteractiveMovementForItemAtIndexPath:indexPath];
1042+
}
1043+
1044+
- (void)endInteractiveMovement {
1045+
_editting = NO;
1046+
return [super endInteractiveMovement];
1047+
}
1048+
1049+
- (void)cancelInteractiveMovement {
1050+
_editting = NO;
1051+
[super cancelInteractiveMovement];
10271052
}
10281053

10291054
#pragma mark -

0 commit comments

Comments
 (0)