Skip to content

Commit

Permalink
BugFix: multiple swipes at a time display delete action
Browse files Browse the repository at this point in the history
  • Loading branch information
BLeeEZ committed Jun 17, 2024
1 parent d6e1ff7 commit 1617208
Showing 1 changed file with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class BasicTableViewController: KeyCommandTableViewController {
var playContextAtIndexPathCallback: PlayContextAtIndexPathCallback?
var swipeCallback: SwipeActionCallback?
var isEditLockedDueToActiveSwipe = false
var isSingleCellEditingModeActive = false

override func viewDidLoad() {
super.viewDidLoad()
Expand All @@ -97,12 +98,20 @@ class BasicTableViewController: KeyCommandTableViewController {
}
updateSearchResults(for: searchController)
}

override func tableView(_ tableView: UITableView, willBeginEditingRowAt indexPath: IndexPath) {
isSingleCellEditingModeActive = true
}

override func tableView(_ tableView: UITableView, didEndEditingRowAt indexPath: IndexPath?) {
isSingleCellEditingModeActive = false
}

override func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
guard let swipeCB = swipeCallback,
let containableCB = containableAtIndexPathCallback,
let containable = containableCB(indexPath)
else { return nil }
else { return UISwipeActionsConfiguration() }

var createdActionsIndex = 0
var actions = [UIContextualAction]()
Expand All @@ -116,11 +125,14 @@ class BasicTableViewController: KeyCommandTableViewController {
}

override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
guard !tableView.isEditing else { return nil }
// return nil here allows to display the "Delete" confirmation swipe action in edit mode (nil -> show default action -> delete is the default one)
guard !(tableView.isEditing && !isSingleCellEditingModeActive) else { return nil }
// this empty configuration enshures to only perform one "Delete" action at a time (no confirmation is displayed)
guard !(tableView.isEditing && isSingleCellEditingModeActive) else { return UISwipeActionsConfiguration() }
guard let swipeCB = swipeCallback,
let containableCB = containableAtIndexPathCallback,
let containable = containableCB(indexPath)
else { return nil }
else { return UISwipeActionsConfiguration() }
var createdActionsIndex = 0
var actions = [UIContextualAction]()
for actionType in appDelegate.storage.settings.swipeActionSettings.trailing {
Expand Down

0 comments on commit 1617208

Please sign in to comment.