From d2125c9632ecf8502287fbad10258683db4f4df3 Mon Sep 17 00:00:00 2001 From: Nick Sillik Date: Thu, 4 Jan 2024 11:33:28 -0500 Subject: [PATCH] Some work to match UITableView's defaults even better --- ListableUI/Sources/Internal/SwipeActionsView.swift | 7 ++++++- ListableUI/Sources/Internal/SwipeActionsViewStyle.swift | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ListableUI/Sources/Internal/SwipeActionsView.swift b/ListableUI/Sources/Internal/SwipeActionsView.swift index 3c87c07d..33232b5d 100644 --- a/ListableUI/Sources/Internal/SwipeActionsView.swift +++ b/ListableUI/Sources/Internal/SwipeActionsView.swift @@ -182,7 +182,8 @@ final class SwipeActionsView: UIView { case .sizeThatFits: return buttons.map { - max($0.sizeThatFits(UIView.layoutFittingCompressedSize).width, style.minWidth) + let x = max($0.sizeThatFits(UIView.layoutFittingCompressedSize).width, style.minWidth) + return min(style.maxItemWidth, x) } .reduce(0, +) + spacingWidth } @@ -265,6 +266,10 @@ private class DefaultSwipeActionButton: UIButton { titleLabel?.font = .systemFont(ofSize: 15, weight: .medium) titleLabel?.lineBreakMode = .byTruncatingTail + titleLabel?.numberOfLines = 2 + titleLabel?.minimumScaleFactor = 0.8 + titleLabel?.adjustsFontSizeToFitWidth = true + titleLabel?.textAlignment = .center contentEdgeInsets = UIEdgeInsets(top: 0, left: inset, bottom: 0, right: inset) addTarget(self, action: #selector(onTap), for: .primaryActionTriggered) } diff --git a/ListableUI/Sources/Internal/SwipeActionsViewStyle.swift b/ListableUI/Sources/Internal/SwipeActionsViewStyle.swift index 307f1571..8057052b 100644 --- a/ListableUI/Sources/Internal/SwipeActionsViewStyle.swift +++ b/ListableUI/Sources/Internal/SwipeActionsViewStyle.swift @@ -32,7 +32,10 @@ public struct SwipeActionsViewStyle: Equatable { public var containerCornerRadius: CGFloat public var buttonSizing: ButtonSizing public var minWidth: CGFloat - + + /// The maximum width of individual items. Defaults to 120, matching `UITableView` + public var maxItemWidth: CGFloat + /// The percentage of the row content width that is available for laying out swipe action buttons. /// /// For example, a value of `0.8` represents that the swipe action buttons should occupy no more than @@ -48,6 +51,7 @@ public struct SwipeActionsViewStyle: Equatable { containerCornerRadius: CGFloat = 0, buttonSizing: ButtonSizing = .sizeThatFits, minWidth: CGFloat = 0, + maxItemWidth: CGFloat = 120, maxWidthRatio: CGFloat = 0.8 ) { self.actionShape = actionShape @@ -57,6 +61,7 @@ public struct SwipeActionsViewStyle: Equatable { self.containerCornerRadius = containerCornerRadius self.buttonSizing = buttonSizing self.minWidth = minWidth + self.maxItemWidth = maxItemWidth self.maxWidthRatio = maxWidthRatio }