Replace UITableViewRowAction with UIContextualAction
This commit is contained in:
parent
2cc161f0c0
commit
37482d3b69
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -24,7 +24,9 @@ open class TableRow<CellType: ConfigurableCell>: Row where CellType: UITableView
|
|||
|
||||
public let item: CellType.CellData
|
||||
private lazy var actions = [String: [TableRowAction<CellType>]]()
|
||||
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<CellType: ConfigurableCell>: Row where CellType: UITableView
|
|||
return CellType.self
|
||||
}
|
||||
|
||||
public init(item: CellType.CellData, actions: [TableRowAction<CellType>]? = nil, editingActions: [UITableViewRowAction]? = nil) {
|
||||
public init(item: CellType.CellData,
|
||||
actions: [TableRowAction<CellType>]? = 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<CellType: ConfigurableCell>: 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 -
|
||||
|
|
|
|||
|
|
@ -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)";
|
||||
|
|
|
|||
Loading…
Reference in New Issue