Skip to content

Commit

Permalink
Some work to match UITableView's defaults even better
Browse files Browse the repository at this point in the history
  • Loading branch information
nsillik committed Jan 5, 2024
1 parent aea7f4c commit 1b6c352
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 6 additions & 1 deletion ListableUI/Sources/Internal/SwipeActionsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ final class SwipeActionsView: UIView {

case .sizeThatFits:
return buttons.map {
max($0.sizeThatFits(UIView.layoutFittingCompressedSize).width, style.minWidth)
let minWidth = max($0.sizeThatFits(UIView.layoutFittingCompressedSize).width, style.minWidth)
return min(style.maxItemWidth, minWidth)
}
.reduce(0, +) + spacingWidth
}
Expand Down Expand Up @@ -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)
}
Expand Down
9 changes: 7 additions & 2 deletions ListableUI/Sources/Internal/SwipeActionsViewStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -48,7 +51,8 @@ public struct SwipeActionsViewStyle: Equatable {
containerCornerRadius: CGFloat = 0,
buttonSizing: ButtonSizing = .sizeThatFits,
minWidth: CGFloat = 0,
maxWidthRatio: CGFloat = 0.8
maxWidthRatio: CGFloat = 0.8,
maxItemWidth: CGFloat = 120
) {
self.actionShape = actionShape
self.interActionSpacing = interActionSpacing
Expand All @@ -57,6 +61,7 @@ public struct SwipeActionsViewStyle: Equatable {
self.containerCornerRadius = containerCornerRadius
self.buttonSizing = buttonSizing
self.minWidth = minWidth
self.maxItemWidth = maxItemWidth
self.maxWidthRatio = maxWidthRatio
}

Expand Down

0 comments on commit 1b6c352

Please sign in to comment.