diff --git a/.gitignore b/.gitignore index 222e8ec..7754794 100755 --- a/.gitignore +++ b/.gitignore @@ -34,6 +34,7 @@ playground.xcworkspace # Swift Package Manager .build/ +.swiftpm/ # Carthage Carthage/Build diff --git a/Demo/TableKitDemo.xcodeproj/project.pbxproj b/Demo/TableKitDemo.xcodeproj/project.pbxproj index eef710e..81999da 100644 --- a/Demo/TableKitDemo.xcodeproj/project.pbxproj +++ b/Demo/TableKitDemo.xcodeproj/project.pbxproj @@ -373,7 +373,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -422,7 +422,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; @@ -439,7 +439,7 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; INFOPLIST_FILE = Resources/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.tablekit.demo; PRODUCT_NAME = TableKitDemo; @@ -456,7 +456,7 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; INFOPLIST_FILE = Resources/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.tablekit.demo; PRODUCT_NAME = TableKitDemo; diff --git a/Package.swift b/Package.swift index 5ce7c3d..d5b2d0f 100644 --- a/Package.swift +++ b/Package.swift @@ -5,7 +5,11 @@ import PackageDescription let package = Package( name: "TableKit", - + + platforms: [ + .iOS(.v9) + ], + products: [ .library( name: "TableKit", diff --git a/Sources/TableDirector.swift b/Sources/TableDirector.swift index 2ffc99d..bdf9851 100644 --- a/Sources/TableDirector.swift +++ b/Sources/TableDirector.swift @@ -343,6 +343,7 @@ open class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate { } // MARK: - Row editing + open func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { return sections[indexPath.section].rows[indexPath.row].isEditingAllowed(forIndexPath: indexPath) } @@ -351,6 +352,30 @@ open class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate { return sections[indexPath.section].rows[indexPath.row].editingActions } + @available(iOS 11, *) + open func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? { + 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? { + guard sections[indexPath.section].rows[indexPath.row].editingActions?.isEmpty ?? true else { + return nil + } + + 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 { if invoke(action: .canDelete, cell: tableView.cellForRow(at: indexPath), indexPath: indexPath) as? Bool ?? false { return UITableViewCell.EditingStyle.delete @@ -380,10 +405,10 @@ open class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate { open func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) { invoke(action: .move, cell: tableView.cellForRow(at: sourceIndexPath), indexPath: sourceIndexPath, userInfo: [TableKitUserInfoKeys.CellMoveDestinationIndexPath: destinationIndexPath]) } - + open func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) { - let cell = tableView.cellForRow(at: indexPath) - invoke(action: .accessoryButtonTap, cell: cell, indexPath: indexPath) + let cell = tableView.cellForRow(at: indexPath) + invoke(action: .accessoryButtonTap, cell: cell, indexPath: indexPath) } } diff --git a/Sources/TableKit.swift b/Sources/TableKit.swift index 526b378..8f8ff2e 100644 --- a/Sources/TableKit.swift +++ b/Sources/TableKit.swift @@ -36,8 +36,18 @@ public protocol RowConfigurable { } public protocol RowActionable { - + + @available(iOS 11, *) + var leadingContextualActions: [UIContextualAction] { get } + + @available(iOS 11, *) + var trailingContextualActions: [UIContextualAction] { get } + + @available(iOS 11, *) + var performsFirstActionWithFullSwipe: Bool { get } + var editingActions: [UITableViewRowAction]? { get } + func isEditingAllowed(forIndexPath indexPath: IndexPath) -> Bool func invoke( diff --git a/Sources/TableRow.swift b/Sources/TableRow.swift index b04382d..76ffee3 100644 --- a/Sources/TableRow.swift +++ b/Sources/TableRow.swift @@ -24,7 +24,24 @@ open class TableRow: Row where CellType: UITableView public let item: CellType.CellData private lazy var actions = [String: [TableRowAction]]() - private(set) open var editingActions: [UITableViewRowAction]? + + @available(iOS, deprecated: 11, message: "Use leadingContextualActions, trailingContextualActions instead") + open private(set) var editingActions: [UITableViewRowAction]? + + @available(iOS 11, *) + open var leadingContextualActions: [UIContextualAction] { + [] + } + + @available(iOS 11, *) + open var trailingContextualActions: [UIContextualAction] { + [] + } + + @available(iOS 11, *) + open var performsFirstActionWithFullSwipe: Bool { + false + } open var hashValue: Int { return ObjectIdentifier(self).hashValue @@ -46,13 +63,20 @@ open class TableRow: Row where CellType: UITableView return CellType.self } + @available(iOS, deprecated: 11, message: "Use init(item:_, actions:_) with leadingContextualActions, trailingContextualActions instead") public init(item: CellType.CellData, actions: [TableRowAction]? = nil, editingActions: [UITableViewRowAction]? = nil) { self.item = item self.editingActions = editingActions actions?.forEach { on($0) } } - + + public init(item: CellType.CellData, actions: [TableRowAction]? = nil) { + + self.item = item + actions?.forEach { on($0) } + } + // MARK: - RowConfigurable - open func configure(_ cell: UITableViewCell) { @@ -77,7 +101,15 @@ 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 + + if #available(iOS 11, *) { + return editingActions?.isEmpty == false + || !leadingContextualActions.isEmpty + || !trailingContextualActions.isEmpty + || actions[TableRowActionType.clickDelete.key] != nil + } else { + return editingActions?.isEmpty == false || actions[TableRowActionType.clickDelete.key] != nil + } } // MARK: - actions - diff --git a/TableKit.podspec b/TableKit.podspec index 2db6237..5dbb70f 100644 --- a/TableKit.podspec +++ b/TableKit.podspec @@ -9,8 +9,8 @@ Pod::Spec.new do |s| s.author = { 'Max Sokolov' => 'i@maxsokolov.net' } s.license = { :type => 'MIT', :file => 'LICENSE' } - s.platforms = { :ios => '8.0' } - s.ios.deployment_target = '8.0' + s.platforms = { :ios => '9.0' } + s.ios.deployment_target = '9.0' s.source_files = 'Sources/*.swift' s.source = { :git => 'https://github.com/maxsokolov/TableKit.git', :tag => s.version } diff --git a/TableKit.xcodeproj/project.pbxproj b/TableKit.xcodeproj/project.pbxproj index d20f8ba..0a12164 100644 --- a/TableKit.xcodeproj/project.pbxproj +++ b/TableKit.xcodeproj/project.pbxproj @@ -311,7 +311,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -365,7 +365,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; @@ -388,7 +388,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 = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.tablekit.TableKit; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -409,7 +409,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 = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.tablekit.TableKit; PRODUCT_NAME = "$(TARGET_NAME)";