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

Add support for more modern (non-deprecated) table view swipe API #154

Open
wants to merge 1 commit 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
5 changes: 2 additions & 3 deletions Static.podspec
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
Pod::Spec.new do |spec|
spec.name = 'Static'
spec.version = '4.0.2'
spec.version = '4.1.0'
spec.summary = 'Simple static table views for iOS in Swift.'
spec.description = 'Static provides simple static table views for iOS in Swift.'
spec.homepage = 'https://github.com/venmo/static'
spec.license = { type: 'MIT', file: 'LICENSE' }
spec.source = { git: 'https://github.com/venmo/Static.git', tag: "v#{spec.version}" }
spec.author = { 'Venmo' => '[email protected]', 'Sam Soffes' => '[email protected]' }

spec.platform = :ios, '8.0'
spec.ios.deployment_target = '11.0'
spec.frameworks = 'UIKit'
spec.source_files = 'Static/*.{swift,h}'
end
16 changes: 16 additions & 0 deletions Static/DataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,22 @@ extension DataSource: UITableViewDataSource {
return rowAction
}
}

public func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
return row(at: indexPath)?.leadingSwipeActionsConfiguration.map {
let actionsConfiguration = UISwipeActionsConfiguration(actions: $0.actions)
actionsConfiguration.performsFirstActionWithFullSwipe = $0.performsFirstActionWithFullSwipe
return actionsConfiguration
}
}

public func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
return row(at: indexPath)?.trailingSwipeActionsConfiguration.map {
let actionsConfiguration = UISwipeActionsConfiguration(actions: $0.actions)
actionsConfiguration.performsFirstActionWithFullSwipe = $0.performsFirstActionWithFullSwipe
return actionsConfiguration
}
}

public func sectionIndexTitles(for tableView: UITableView) -> [String]? {
guard let sectionIndexTitles = sectionIndexTitles, sectionIndexTitles.count >= sections.count else { return nil }
Expand Down
21 changes: 20 additions & 1 deletion Static/Row.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,19 @@ public struct Row: Hashable, Equatable {
self.selection = selection
}
}

/// Representation of the set of actions to perform when swiping on rows of a table.
public struct SwipeActionsConfiguration {
/// The swipe actions.
public let actions: [UIContextualAction]

/// A Boolean value indicating whether a full swipe automatically performs the first action.
public var performsFirstActionWithFullSwipe: Bool = true

public init(actions: [UIContextualAction]) {
self.actions = actions
}
}

// MARK: - Properties

Expand Down Expand Up @@ -137,9 +150,15 @@ public struct Row: Hashable, Equatable {

/// Actions to show when swiping the cell, such as Delete.
public var editActions: [EditAction]

/// Returns the swipe actions to display on the leading edge of the row.
public var leadingSwipeActionsConfiguration: SwipeActionsConfiguration?

/// Returns the swipe actions to display on the trailing edge of the row.
public var trailingSwipeActionsConfiguration: SwipeActionsConfiguration?

var canEdit: Bool {
return editActions.count > 0
return (editActions.count > 0) || (leadingSwipeActionsConfiguration != nil) || (trailingSwipeActionsConfiguration != nil)
}

var isSelectable: Bool {
Expand Down