larryryu / LSSwipeToDeleteCollectionViewLayout

The UICollectionViewLayout subclass adds swipe to delete functionality to a collectionview
MIT License
41 stars 4 forks source link

Added additional validations and callback methods to layout #6

Closed batkru closed 9 years ago

batkru commented 9 years ago

I added certain additional validations in regards to whether the deletion should happen as well as fixing a bug of calling deleting index too soon.

larryryu commented 9 years ago

Looks good! The only issue i have is the check for wether or not the deletion should occur.

it was previously

if (!shouldDelete || gesture.state == UIGestureRecognizerStateFailed 
|| gesture.state == UIGestureRecognizerStateCancelled) {
    [self cancelSwipeToDeleteWithCompletion:completionBlock];
}else{
    NSArray *indexPathsToDelete = @[selectedIndexPath];
    [self performSwipeToDeleteForCellsAtIndexPaths:indexPathsToDelete withCompletion:completionBlock];
}

and now

if (!shouldDelete || gesture.state == UIGestureRecognizerStateFailed || 
gesture.state == UIGestureRecognizerStateCancelled || 
[self translationValue] < self.deletionDistanceTresholdValue || 
[self velocityMagnitude] < self.deletionVelocityTresholdValue || 
[self velocity] > 0) {
    [self cancelSwipeToDeleteWithCompletion:completionBlock];
}else{
    NSArray *indexPathsToDelete = @[selectedIndexPath];
    [self performSwipeToDeleteForCellsAtIndexPaths:indexPathsToDelete withCompletion:completionBlock];
}

i don't think the extra checks are necessary.

[self translationValue] < self.deletionDistanceTresholdValue || 
[self velocityMagnitude] < self.deletionVelocityTresholdValue ||
 [self velocity] > 0

see how 'shouldDelete' is setup

userTriggerredSwipeToDeleteDirection = [self deletionDirectionWithGestureRecogniser:gesture];
BOOL shouldDelete = (userTriggerredSwipeToDeleteDirection != LSSwipeToDeleteDirectionNone);

also look at the implementation of the method below

- (void)deletionDirectionWithGestureRecogniser;