Skip to content

Commit 1617208

Browse files
committed
BugFix: multiple swipes at a time display delete action
1 parent d6e1ff7 commit 1617208

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

Amperfy/Screens/ViewController/TableViewHelper/BasicTableViewController.swift

+15-3
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class BasicTableViewController: KeyCommandTableViewController {
8282
var playContextAtIndexPathCallback: PlayContextAtIndexPathCallback?
8383
var swipeCallback: SwipeActionCallback?
8484
var isEditLockedDueToActiveSwipe = false
85+
var isSingleCellEditingModeActive = false
8586

8687
override func viewDidLoad() {
8788
super.viewDidLoad()
@@ -97,12 +98,20 @@ class BasicTableViewController: KeyCommandTableViewController {
9798
}
9899
updateSearchResults(for: searchController)
99100
}
101+
102+
override func tableView(_ tableView: UITableView, willBeginEditingRowAt indexPath: IndexPath) {
103+
isSingleCellEditingModeActive = true
104+
}
105+
106+
override func tableView(_ tableView: UITableView, didEndEditingRowAt indexPath: IndexPath?) {
107+
isSingleCellEditingModeActive = false
108+
}
100109

101110
override func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
102111
guard let swipeCB = swipeCallback,
103112
let containableCB = containableAtIndexPathCallback,
104113
let containable = containableCB(indexPath)
105-
else { return nil }
114+
else { return UISwipeActionsConfiguration() }
106115

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

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

0 commit comments

Comments
 (0)