From efc03d7c223623ef1f38d2a606bac5eceb64ed05 Mon Sep 17 00:00:00 2001 From: Vlad Date: Sat, 26 Dec 2020 11:24:59 +0300 Subject: [PATCH] Add performsFirstActionWithFullSwipe --- Sources/TableDirector.swift | 14 ++++++++++++-- Sources/TableKit.swift | 3 +++ Sources/TableRow.swift | 5 +++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Sources/TableDirector.swift b/Sources/TableDirector.swift index cc99f16..e5e2564 100644 --- a/Sources/TableDirector.swift +++ b/Sources/TableDirector.swift @@ -355,13 +355,23 @@ open class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate { @available(iOS 11, *) open func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? { - return .init(actions: sections[indexPath.section].rows[indexPath.row].leadingContextualActions) + let currentRow = sections[indexPath.section].rows[indexPath.row] + let configuration = UISwipeActionsConfiguration(actions: currentRow.leadingContextualActions) + + configuration.performsFirstActionWithFullSwipe = currentRow.performsFirstActionWithFullSwipe + + return configuration } @available(iOS 11, *) open func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? { - return .init(actions: sections[indexPath.section].rows[indexPath.row].trailingContextualActions) + let currentRow = sections[indexPath.section].rows[indexPath.row] + let configuration = UISwipeActionsConfiguration(actions: currentRow.trailingContextualActions) + + configuration.performsFirstActionWithFullSwipe = currentRow.performsFirstActionWithFullSwipe + + return configuration } open func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCell.EditingStyle { diff --git a/Sources/TableKit.swift b/Sources/TableKit.swift index e3f25f4..65ae26d 100644 --- a/Sources/TableKit.swift +++ b/Sources/TableKit.swift @@ -44,6 +44,9 @@ public protocol RowActionable { @available(iOS 11, *) var trailingContextualActions: [UIContextualAction] { get } + @available(iOS 11, *) + var performsFirstActionWithFullSwipe: Bool { get } + @available(iOS, obsoleted: 11, message: "Use leadingContextualActions, trailingContextualActions instead") var editingActions: [UITableViewRowAction]? { get } diff --git a/Sources/TableRow.swift b/Sources/TableRow.swift index 356693e..f78a4b3 100644 --- a/Sources/TableRow.swift +++ b/Sources/TableRow.swift @@ -38,6 +38,11 @@ open class TableRow: Row where CellType: UITableView [] } + @available(iOS 11, *) + open var performsFirstActionWithFullSwipe: Bool { + false + } + open var hashValue: Int { return ObjectIdentifier(self).hashValue }