diff --git a/Sources/TableDirector.swift b/Sources/TableDirector.swift index 2ffc99d..10e6390 100644 --- a/Sources/TableDirector.swift +++ b/Sources/TableDirector.swift @@ -348,7 +348,17 @@ open class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate { } open func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? { - return sections[indexPath.section].rows[indexPath.row].editingActions + return nil + } + + open func tableView(_ tableView: UITableView, + leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? { + return .init(actions: sections[indexPath.section].rows[indexPath.row].leadingContextualActions) + } + + open func tableView(_ tableView: UITableView, + trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? { + return .init(actions: sections[indexPath.section].rows[indexPath.row].trailingContextualActions) } open func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCell.EditingStyle { diff --git a/Sources/TableKit.swift b/Sources/TableKit.swift index 0615871..97b48ec 100644 --- a/Sources/TableKit.swift +++ b/Sources/TableKit.swift @@ -38,7 +38,9 @@ public protocol RowConfigurable { public protocol RowActionable { - var editingActions: [UITableViewRowAction]? { get } + var leadingContextualActions: [UIContextualAction] { get } + var trailingContextualActions: [UIContextualAction] { get } + func isEditingAllowed(forIndexPath indexPath: IndexPath) -> Bool func invoke( diff --git a/Sources/TableRow.swift b/Sources/TableRow.swift index 662b4dd..467dfec 100644 --- a/Sources/TableRow.swift +++ b/Sources/TableRow.swift @@ -24,7 +24,9 @@ open class TableRow: Row where CellType: UITableView public let item: CellType.CellData private lazy var actions = [String: [TableRowAction]]() - private(set) open var editingActions: [UITableViewRowAction]? + + private(set) open var leadingContextualActions: [UIContextualAction] = [] + private(set) open var trailingContextualActions: [UIContextualAction] = [] open var hashValue: Int { return ObjectIdentifier(self).hashValue @@ -50,10 +52,15 @@ open class TableRow: Row where CellType: UITableView return CellType.self } - public init(item: CellType.CellData, actions: [TableRowAction]? = nil, editingActions: [UITableViewRowAction]? = nil) { + public init(item: CellType.CellData, + actions: [TableRowAction]? = nil, + leadingContextualActions: [UIContextualAction] = [], + trailingContextualActions: [UIContextualAction] = []) { self.item = item - self.editingActions = editingActions + self.leadingContextualActions = leadingContextualActions + self.trailingContextualActions = trailingContextualActions + actions?.forEach { on($0) } } @@ -81,7 +88,10 @@ open class TableRow: Row where CellType: UITableView if actions[TableRowActionType.canEdit.key] != nil { return invoke(action: .canEdit, cell: nil, path: indexPath) as? Bool ?? false } - return editingActions?.isEmpty == false || actions[TableRowActionType.clickDelete.key] != nil + + return !leadingContextualActions.isEmpty + || !trailingContextualActions.isEmpty + || actions[TableRowActionType.clickDelete.key] != nil } // MARK: - actions - diff --git a/TableKit.xcodeproj/project.pbxproj b/TableKit.xcodeproj/project.pbxproj index 990d148..d097f6a 100644 --- a/TableKit.xcodeproj/project.pbxproj +++ b/TableKit.xcodeproj/project.pbxproj @@ -412,7 +412,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = "$(SRCROOT)/Configs/TableKit.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.tablekit.TableKit; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -433,7 +433,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = "$(SRCROOT)/Configs/TableKit.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.tablekit.TableKit; PRODUCT_NAME = "$(TARGET_NAME)";