Skip to content

Add shouldDelete*At methods to swipe cell delegates, invoke on swipe animation completion#415

Open
p4checo wants to merge 2 commits intoSwipeCellKit:developfrom
p4checo:add-should-delete-at-delegate-method
Open

Add shouldDelete*At methods to swipe cell delegates, invoke on swipe animation completion#415
p4checo wants to merge 2 commits intoSwipeCellKit:developfrom
p4checo:add-should-delete-at-delegate-method

Conversation

@p4checo
Copy link
Copy Markdown

@p4checo p4checo commented May 5, 2021

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.

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 to SwipeCollectionViewCellDelegate, and invoke it on SwipeCollectionViewCell.swipeController(:didDeleteSwipeableAt:).

  • Add new tableView(:shouldDeleteRowAt:) delegate method to SwipeTableViewCellDelegate and invoke it on SwipeTableViewCell.swipeController(:didDeleteSwipeableAt:).

  • 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.

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:)`.
@p4checo p4checo force-pushed the add-should-delete-at-delegate-method branch from dc8ac66 to d595356 Compare May 5, 2021 17:43
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`.
@p4checo p4checo changed the title Add shouldDelete*At methods to swipe cell delegates Add shouldDelete*At methods to swipe cell delegates, invoke on swipe animation completion May 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant