Skip to content
This repository has been archived by the owner on May 3, 2023. It is now read-only.

Commit

Permalink
Fix collection cell editing bug for iOS 9 & 10
Browse files Browse the repository at this point in the history
  • Loading branch information
wsdwsd0829 committed Aug 22, 2018
1 parent a63d438 commit 06e18a1
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions Source/ASCollectionView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ @interface ASCollectionView () <ASRangeControllerDataSource, ASRangeControllerDe
* (0 sections) we always check at least once after each update (initial reload is the first update.)
*/
BOOL _hasEverCheckedForBatchFetchingDueToUpdate;

/**
* Set during beginInteractiveMovementForItemAtIndexPath and UIGestureRecognizerStateEnded
* (or UIGestureRecognizerStateFailed, UIGestureRecognizerStateCancelled.
*/
BOOL _editting;

/**
* Counter used to keep track of nested batch updates.
Expand Down Expand Up @@ -1021,9 +1027,28 @@ - (void)reloadItemsAtIndexPaths:(NSArray *)indexPaths
- (void)moveItemAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath
{
ASDisplayNodeAssertMainThread();
[self performBatchUpdates:^{
[_changeSet moveItemAtIndexPath:indexPath toIndexPath:newIndexPath animationOptions:kASCollectionViewAnimationNone];
} completion:nil];
if (!_editting) {
[self performBatchUpdates:^{
[_changeSet moveItemAtIndexPath:indexPath toIndexPath:newIndexPath animationOptions:kASCollectionViewAnimationNone];
} completion:nil];
} else {
[super moveItemAtIndexPath:indexPath toIndexPath:newIndexPath];
}
}

- (BOOL)beginInteractiveMovementForItemAtIndexPath:(NSIndexPath *)indexPath {
_editting = YES;
return [super beginInteractiveMovementForItemAtIndexPath:indexPath];
}

- (void)endInteractiveMovement {
_editting = NO;
return [super endInteractiveMovement];
}

- (void)cancelInteractiveMovement {
_editting = NO;
[super cancelInteractiveMovement];
}

#pragma mark -
Expand Down

0 comments on commit 06e18a1

Please sign in to comment.