Add shouldDelete*At methods to swipe cell delegates, invoke on swipe animation completion#415
Open
p4checo wants to merge 2 commits intoSwipeCellKit:developfrom
Open
Conversation
Currently both `SwipeCollectionViewCell` and `SwipeTableViewCell` automatically delete the cells on `swipeController(: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: - Data-driven setups that use diffing - Customize the deletion animation (table view) To achieve that, a new delegate method was added to both the `SwipeCollectionViewCellDelegate` and `SwipeTableViewCellDelegate` to allow customizing the deletion on the container, having the current implementations as the default in protocol extensions. ## Changes - Add new `collectionView(:shouldDeleteItemAt:)` delegate method to `SwipeCollectionViewCellDelegate`, and invoke it on `SwipeCollectionViewCell.swipeController(:didDeleteSwipeableAt:)`. - Add new `tableView(:shouldDeleteRowAt:)` delegate method to `SwipeTableViewCellDelegate` and invoke it on `SwipeTableViewCell.swipeController(:didDeleteSwipeableAt:)`.
dc8ac66 to
d595356
Compare
Following the previous 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 - Invoke `swipeController(:didDeleteSwipeableAt:)` delegate call on delete animation completion - Remove reset logic from `SwipeController`'s delete animation completion closure, moving it to cell's `prepareForReuse`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
SwipeCollectionViewCellandSwipeTableViewCellautomatically 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
SwipeCollectionViewCellDelegateandSwipeTableViewCellDelegateto 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
prepareForReuseof 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 toSwipeTableViewCellDelegateand 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.