From 39c660067360d86ecadbabb444509798ecb79c1b Mon Sep 17 00:00:00 2001 From: Geylan Kalaf Mohe Date: Tue, 3 Dec 2024 07:45:30 +0300 Subject: [PATCH] fix ios 13 deprecation of UITableViewRowAction --- .DS_Store | Bin 0 -> 6148 bytes Sources/Static/DataSource.swift | 25 +++++++++++-------------- Sources/Static/Row.swift | 5 +++-- Static.xcodeproj/project.pbxproj | 8 ++++++-- 4 files changed, 20 insertions(+), 18 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..d3f47a4eb33cdf1ffcc4dfe8bb3ef6b722374aea GIT binary patch literal 6148 zcmeHK%}N773{JF%1uuK_IN)9A8;oUp>2+Vgwk!V7vP)6ut@A`ahA-la_+=8Mi*qO* zL?nUa%g!Y8^TEzch=^w|-IS;%q6#X=;uJ)hi(O|HJOOeZ4MYqm?GvEw-F(BtdfC@&#q?nHmm|Ow?BLriu+98gyl|c!?CJbEozP a@evmdlcJ0w?KvIj4}naG8)x7b82A9k>^k`X literal 0 HcmV?d00001 diff --git a/Sources/Static/DataSource.swift b/Sources/Static/DataSource.swift index 49eccc8..f161cb9 100644 --- a/Sources/Static/DataSource.swift +++ b/Sources/Static/DataSource.swift @@ -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]? { diff --git a/Sources/Static/Row.swift b/Sources/Static/Row.swift index 4909870..31425b6 100644 --- a/Sources/Static/Row.swift +++ b/Sources/Static/Row.swift @@ -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? @@ -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 @@ -104,6 +104,7 @@ public struct Row: Hashable, Equatable { } } + // MARK: - Properties /// The row's accessibility properties. diff --git a/Static.xcodeproj/project.pbxproj b/Static.xcodeproj/project.pbxproj index 33e4c31..d0a8e81 100644 --- a/Static.xcodeproj/project.pbxproj +++ b/Static.xcodeproj/project.pbxproj @@ -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; @@ -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; @@ -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)"; @@ -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)"; @@ -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)"; @@ -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)";