Kanha-Dev / Todoey-iOS13

Todo List App
1 stars 1 forks source link

Animation Bug #2

Open LowkeyCoder2000 opened 4 months ago

LowkeyCoder2000 commented 4 months ago

I believe that the there is a deletion problem.When deleting the cell animation is not fully shown. I've ran into this problem before and this is what worked for me:

swipeAction.fulfill(with: .delete)

extension ListsViewController: SwipeTableViewCellDelegate {
    func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) -> [SwipeAction]? {
        guard orientation == .right else { return nil }
        let list = lists[indexPath.row]

        let deleteAction = SwipeAction(style: .destructive, title: "Delete") { [weak self] swipeAction, indexPath in
            guard let self = self else { return }

            // Trigger the swipe animation
            swipeAction.fulfill(with: .delete)

            // Perform the actual deletion and UI update with a slight delay to allow the swipe animation to complete
            DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
                // Perform the actual deletion from your data source
                self.store.deleteList(list)

                // Update the data source
                self.lists.remove(at: indexPath.row)

                // Update the table view
                tableView.beginUpdates()
                tableView.deleteRows(at: [indexPath], with: .automatic)
                tableView.endUpdates()
            }
        }

        return [deleteAction]
    }

    func tableView(_ tableView: UITableView, editActionsOptionsForRowAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) -> SwipeOptions {
        var options = SwipeOptions()
        options.expansionStyle = .destructive
        return options
    }
}
Kanha-Dev commented 4 months ago

I implemented it a bit differently by leveraging the SwipeCellKit Library. Specifically, I utilized the .destructiveAfterFill property value for that. Additionally, there is no need for DispatchQueue.main.async for updating the view on the main thread in this context.

Here is the code demonstrating how it's implemented:

func tableView(_ tableView: UITableView, editActionsOptionsForRowAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) -> SwipeOptions {
    var options = SwipeOptions()
    options.expansionStyle = .destructiveAfterFill

    return options
}

This approach ensures the desired behavior without the need for additional thread management or any delay handling.