Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace UITableViewRowAction with UIContextualAction, up iphoneos_deployment_target to 9.0 #100

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ playground.xcworkspace

# Swift Package Manager
.build/
.swiftpm/

# Carthage
Carthage/Build
8 changes: 4 additions & 4 deletions Demo/TableKitDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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";
Expand All @@ -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;
Expand All @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import PackageDescription

let package = Package(
name: "TableKit",


platforms: [
.iOS(.v9)
],

products: [
.library(
name: "TableKit",
Expand Down
31 changes: 28 additions & 3 deletions Sources/TableDirector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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
Expand Down Expand Up @@ -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)
}
}

Expand Down
12 changes: 11 additions & 1 deletion Sources/TableKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
38 changes: 35 additions & 3 deletions Sources/TableRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,24 @@ 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]?

@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
Expand All @@ -46,13 +63,20 @@ open class TableRow<CellType: ConfigurableCell>: 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<CellType>]? = nil, editingActions: [UITableViewRowAction]? = nil) {

self.item = item
self.editingActions = editingActions
actions?.forEach { on($0) }
}


public init(item: CellType.CellData, actions: [TableRowAction<CellType>]? = nil) {

self.item = item
actions?.forEach { on($0) }
}

// MARK: - RowConfigurable -

open func configure(_ cell: UITableViewCell) {
Expand All @@ -77,7 +101,15 @@ 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

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 -
Expand Down
4 changes: 2 additions & 2 deletions TableKit.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Pod::Spec.new do |s|

s.author = { 'Max Sokolov' => '[email protected]' }
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 }
Expand Down
8 changes: 4 additions & 4 deletions TableKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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";
Expand All @@ -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)";
Expand All @@ -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)";
Expand Down