Skip to content

Commit

Permalink
Add delete contextual action to OBAListView
Browse files Browse the repository at this point in the history
Fixes a OneBusAway#391 — OBAListView iOS 14 list regression
  • Loading branch information
ualch9 committed Jul 2, 2021
1 parent 5399371 commit 6a17de0
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions OBAKit/Controls/ListView/OBAListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,26 @@ public class OBAListView: UICollectionView, UICollectionViewDelegate {
}

fileprivate func trailingSwipeActions(for indexPath: IndexPath) -> UISwipeActionsConfiguration? {
guard let actions = itemForIndexPath(indexPath)?.trailingContextualActions else { return nil }
guard let item = itemForIndexPath(indexPath) else { return nil }
let contextualActions = item.trailingContextualActions ?? []
var swipeActions = contextualActions.map { $0.contextualAction }

if let deleteAction = item.onDeleteAction {
// Hides "Delete" text if the cell is less than 64 units tall.
let cellSize = self.cellForItem(at: indexPath)?.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize).height ?? 0
let isCellCompact = cellSize < 64
let swipeActionText = isCellCompact ? nil : Strings.delete

let deleteAction = UIContextualAction(style: .destructive, title: swipeActionText) { _, _, success in
deleteAction(item)
success(true)
}
deleteAction.image = Icons.delete

let config = UISwipeActionsConfiguration(actions: actions.map { $0.contextualAction })
swipeActions.append(deleteAction)
}

let config = UISwipeActionsConfiguration(actions: swipeActions)
config.performsFirstActionWithFullSwipe = false

return config
Expand Down

0 comments on commit 6a17de0

Please sign in to comment.