Skip to content
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
Binary file added .DS_Store
Binary file not shown.
25 changes: 11 additions & 14 deletions Sources/Static/DataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -242,27 +242,24 @@ extension DataSource: UITableViewDataSource {
return row(at: indexPath)?.canEdit ?? false
}

@objc(tableView:editActionsForRowAtIndexPath:)
public func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
return row(at: indexPath)?.editActions.map {
action in
let rowAction = UITableViewRowAction(style: action.style, title: action.title) { (_, _) in
@objc(tableView:trailingSwipeActionsConfigurationForRowAtIndexPath:)
public func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
guard let actions = row(at: indexPath)?.editActions else { return nil }

let contextualActions = actions.map { action -> UIContextualAction in
let contextualAction = UIContextualAction(style: action.style == .destructive ? .destructive : .normal, title: action.title) { (_, _, completionHandler) in
action.selection?(indexPath)
completionHandler(true) // Notify the system that the action was performed
}

// These calls have side effects when setting to nil
// Setting a background color to nil will wipe out any predefined style
// Wrapping these in if-lets prevents nil-setting side effects
if let backgroundColor = action.backgroundColor {
rowAction.backgroundColor = backgroundColor
}

if let backgroundEffect = action.backgroundEffect {
rowAction.backgroundEffect = backgroundEffect
contextualAction.backgroundColor = backgroundColor
}

return rowAction
return contextualAction
}

return UISwipeActionsConfiguration(actions: contextualActions)
}

public func sectionIndexTitles(for tableView: UITableView) -> [String]? {
Expand Down
5 changes: 3 additions & 2 deletions Sources/Static/Row.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public struct Row: Hashable, Equatable {
public let title: String

/// Styling for button's action, used primarily for destructive actions.
public let style: UITableViewRowAction.Style
public let style: UIContextualAction.Style

/// Background color of the button.
public let backgroundColor: UIColor?
Expand All @@ -95,7 +95,7 @@ public struct Row: Hashable, Equatable {
/// Invoked when selecting the action.
public let selection: EditActionSelection?

public init(title: String, style: UITableViewRowAction.Style = .default, backgroundColor: UIColor? = nil, backgroundEffect: UIVisualEffect? = nil, selection: EditActionSelection? = nil) {
public init(title: String, style: UIContextualAction.Style = .normal, backgroundColor: UIColor? = nil, backgroundEffect: UIVisualEffect? = nil, selection: EditActionSelection? = nil) {
self.title = title
self.style = style
self.backgroundColor = backgroundColor
Expand All @@ -104,6 +104,7 @@ public struct Row: Hashable, Equatable {
}
}


// MARK: - Properties

/// The row's accessibility properties.
Expand Down
8 changes: 6 additions & 2 deletions Static.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = "$(SRCROOT)/Support/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.venmo.static;
PRODUCT_NAME = Static;
Expand All @@ -568,6 +569,7 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = "$(SRCROOT)/Support/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.venmo.static;
PRODUCT_NAME = Static;
Expand All @@ -582,6 +584,7 @@
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
INFOPLIST_FILE = "Support/Tests-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.venmo.static.tests;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -594,6 +597,7 @@
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
INFOPLIST_FILE = "Support/Tests-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.venmo.static.tests;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -607,7 +611,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = Example/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.venmo.Example;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -620,7 +624,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = Example/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.venmo.Example;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down