Skip to content

Commit 8d2d6ac

Browse files
committed
Add support for more modern (non-deprecated) table view swipe API
UITableViewRowAction and it’s associated methods have been deprecated in favor of the new UISwipeActionsConfiguration object which can be configured on the trailing and leading edges of a table view cell. This API is available on iOS 11.0 onwards. The cleanest way to support this is to bump the deployment target to iOS 11.
1 parent 357afa1 commit 8d2d6ac

3 files changed

Lines changed: 38 additions & 4 deletions

File tree

Static.podspec

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
Pod::Spec.new do |spec|
22
spec.name = 'Static'
3-
spec.version = '4.0.1'
3+
spec.version = '4.1.0'
44
spec.summary = 'Simple static table views for iOS in Swift.'
55
spec.description = 'Static provides simple static table views for iOS in Swift.'
66
spec.homepage = 'https://github.com/venmo/static'
77
spec.license = { type: 'MIT', file: 'LICENSE' }
88
spec.source = { git: 'https://github.com/venmo/Static.git', tag: "v#{spec.version}" }
99
spec.author = { 'Venmo' => 'ios@venmo.com', 'Sam Soffes' => 'sam@soff.es' }
10-
11-
spec.platform = :ios, '8.0'
10+
spec.ios.deployment_target = '11.0'
1211
spec.frameworks = 'UIKit'
1312
spec.source_files = 'Static/*.{swift,h}'
1413
end

Static/DataSource.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,22 @@ extension DataSource: UITableViewDataSource {
264264
return rowAction
265265
}
266266
}
267+
268+
public func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
269+
return row(at: indexPath)?.leadingSwipeActionsConfiguration.map {
270+
let actionsConfiguration = UISwipeActionsConfiguration(actions: $0.actions)
271+
actionsConfiguration.performsFirstActionWithFullSwipe = $0.performsFirstActionWithFullSwipe
272+
return actionsConfiguration
273+
}
274+
}
275+
276+
public func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
277+
return row(at: indexPath)?.trailingSwipeActionsConfiguration.map {
278+
let actionsConfiguration = UISwipeActionsConfiguration(actions: $0.actions)
279+
actionsConfiguration.performsFirstActionWithFullSwipe = $0.performsFirstActionWithFullSwipe
280+
return actionsConfiguration
281+
}
282+
}
267283

268284
public func sectionIndexTitles(for tableView: UITableView) -> [String]? {
269285
guard let sectionIndexTitles = sectionIndexTitles, sectionIndexTitles.count >= sections.count else { return nil }

Static/Row.swift

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,19 @@ public struct Row: Hashable, Equatable {
103103
self.selection = selection
104104
}
105105
}
106+
107+
/// Representation of the set of actions to perform when swiping on rows of a table.
108+
public struct SwipeActionsConfiguration {
109+
/// The swipe actions.
110+
public let actions: [UIContextualAction]
111+
112+
/// A Boolean value indicating whether a full swipe automatically performs the first action.
113+
public var performsFirstActionWithFullSwipe: Bool = true
114+
115+
public init(actions: [UIContextualAction]) {
116+
self.actions = actions
117+
}
118+
}
106119

107120
// MARK: - Properties
108121

@@ -135,9 +148,15 @@ public struct Row: Hashable, Equatable {
135148

136149
/// Actions to show when swiping the cell, such as Delete.
137150
public var editActions: [EditAction]
151+
152+
/// Returns the swipe actions to display on the leading edge of the row.
153+
public var leadingSwipeActionsConfiguration: SwipeActionsConfiguration?
154+
155+
/// Returns the swipe actions to display on the trailing edge of the row.
156+
public var trailingSwipeActionsConfiguration: SwipeActionsConfiguration?
138157

139158
var canEdit: Bool {
140-
return editActions.count > 0
159+
return (editActions.count > 0) || (leadingSwipeActionsConfiguration != nil) || (trailingSwipeActionsConfiguration != nil)
141160
}
142161

143162
var isSelectable: Bool {

0 commit comments

Comments
 (0)