Add shouldDelete*At methods to swipe cell delegates, invoke on swipe animation completion #415
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently both
SwipeCollectionViewCell
andSwipeTableViewCell
automatically delete the cells onswipeController(:didDeleteSwipeableAt:)
and don't allow any customization, like what's allowed in other similar methods.While on most scenarios the default behavior is desired, there are some scenarios where users might want to control how the deletion is effectively made on the container (CollectionView or TableView). Some examples are:
To achieve that, a new delegate method was added to both the
SwipeCollectionViewCellDelegate
andSwipeTableViewCellDelegate
to allow customizing the deletion on the container, having the current implementations as the default in protocol extensions.Following the above changes to the cell deletion flow on swipe completion, the actual cell deletion trigger was moved to the animation completion so that we wait for the swipe animation to complete before actually triggering the cell removal.
To prevent visual artifacts, the reset calls in the animation completion were moved to the
prepareForReuse
of each cell, achieving the same result.Changes
Add new
collectionView(:shouldDeleteItemAt:)
delegate method toSwipeCollectionViewCellDelegate
, and invoke it onSwipeCollectionViewCell.swipeController(:didDeleteSwipeableAt:)
.Add new
tableView(:shouldDeleteRowAt:)
delegate method toSwipeTableViewCellDelegate
and invoke it onSwipeTableViewCell.swipeController(:didDeleteSwipeableAt:)
.Invoke
swipeController(:didDeleteSwipeableAt:)
delegate call on delete animation completionRemove reset logic from
SwipeController
's delete animation completion closure, moving it to cell'sprepareForReuse
.