Skip to content

Commit 742ca9c

Browse files
authored
Merge pull request #8094 from woocommerce/task/contentedgeinsets-deprecated-ios-15
Fix 'contentEdgeInsets' was deprecated in iOS 15.0
2 parents 91905fc + db0bd1d commit 742ca9c

File tree

6 files changed

+63
-15
lines changed

6 files changed

+63
-15
lines changed

WooCommerce/Classes/Extensions/UIButton+Helpers.swift

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ extension UIButton {
88
/// Applies the Primary Button Style: Solid BG!
99
///
1010
func applyPrimaryButtonStyle() {
11-
contentEdgeInsets = Style.defaultEdgeInsets
11+
var configuration = UIButton.Configuration.filled()
12+
configuration.contentInsets = .init(
13+
top: Style.verticalInset,
14+
leading: Style.horizontalInset,
15+
bottom: Style.verticalInset,
16+
trailing: Style.horizontalInset
17+
)
1218
layer.borderColor = UIColor.primaryButtonBorder.cgColor
1319
layer.borderWidth = Style.defaultBorderWidth
1420
layer.cornerRadius = Style.defaultCornerRadius
@@ -39,8 +45,14 @@ extension UIButton {
3945
/// Applies the Secondary Button Style: Clear BG / Bordered Outline
4046
///
4147
func applySecondaryButtonStyle() {
48+
var configuration = UIButton.Configuration.filled()
49+
configuration.contentInsets = .init(
50+
top: Style.verticalInset,
51+
leading: Style.horizontalInset,
52+
bottom: Style.verticalInset,
53+
trailing: Style.horizontalInset
54+
)
4255
backgroundColor = .secondaryButtonBackground
43-
contentEdgeInsets = Style.defaultEdgeInsets
4456
layer.borderColor = UIColor.secondaryButtonBorder.cgColor
4557
layer.borderWidth = Style.defaultBorderWidth
4658
layer.cornerRadius = Style.defaultCornerRadius
@@ -71,8 +83,14 @@ extension UIButton {
7183
/// Applies the Link Button Style: Clear BG / Brand Text Color
7284
///
7385
func applyLinkButtonStyle(enableMultipleLines: Bool = false) {
86+
var configuration = UIButton.Configuration.plain()
87+
configuration.contentInsets = .init(
88+
top: Style.verticalInset,
89+
leading: Style.horizontalInset,
90+
bottom: Style.verticalInset,
91+
trailing: Style.horizontalInset
92+
)
7493
backgroundColor = .clear
75-
contentEdgeInsets = Style.defaultEdgeInsets
7694
tintColor = .accent
7795
titleLabel?.applyBodyStyle()
7896
titleLabel?.textAlignment = .natural
@@ -95,8 +113,14 @@ extension UIButton {
95113
}
96114

97115
func applyPaymentsModalCancelButtonStyle() {
116+
var configuration = UIButton.Configuration.plain()
117+
configuration.contentInsets = .init(
118+
top: Style.verticalInset,
119+
leading: Style.horizontalInset,
120+
bottom: Style.verticalInset,
121+
trailing: Style.horizontalInset
122+
)
98123
backgroundColor = .tertiarySystemBackground
99-
contentEdgeInsets = Style.defaultEdgeInsets
100124
layer.borderColor = UIColor.secondaryButtonBorder.cgColor
101125
layer.borderWidth = Style.defaultBorderWidth
102126
layer.cornerRadius = Style.defaultCornerRadius
@@ -147,7 +171,15 @@ extension UIButton {
147171
private func enableMultipleLines() {
148172
titleLabel?.lineBreakMode = .byWordWrapping
149173
if let label = titleLabel {
150-
pinSubviewToAllEdgeMargins(label)
174+
if self.subviews.contains(where: { $0 == label }) {
175+
pinSubviewToAllEdgeMargins(label)
176+
} else {
177+
DDLogWarn("""
178+
Failed attempt to pin button's title to the edges.
179+
This is likely because the custom button title label was not added to its view hierarchy.
180+
"""
181+
)
182+
}
151183
}
152184
}
153185
}
@@ -160,6 +192,7 @@ private extension UIButton {
160192
struct Style {
161193
static let defaultCornerRadius = CGFloat(8.0)
162194
static let defaultBorderWidth = CGFloat(1.0)
163-
static let defaultEdgeInsets = UIEdgeInsets(top: 12, left: 22, bottom: 12, right: 22)
195+
static let verticalInset = CGFloat(12)
196+
static let horizontalInset = CGFloat(22)
164197
}
165198
}

WooCommerce/Classes/ViewRelated/Orders/Order Details/Customer Section/CustomerNoteTableViewCell.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,9 @@ private extension CustomerNoteTableViewCell {
128128
addButton.setImage(.plusImage, for: .normal)
129129
addButton.contentHorizontalAlignment = .leading
130130
addButton.contentVerticalAlignment = .bottom
131-
addButton.contentEdgeInsets = .zero
131+
var configuration = UIButton.Configuration.plain()
132+
configuration.contentInsets = .init(.zero)
133+
addButton.configuration = configuration
132134
addButton.distributeTitleAndImage(spacing: Constants.buttonTitleAndImageSpacing)
133135
addButton.addTarget(self, action: #selector(addButtonTapped), for: .touchUpInside)
134136
}

WooCommerce/Classes/ViewRelated/Orders/Order Filters/FilteredOrdersHeaderBar.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ private extension FilteredOrdersHeaderBar {
5555
String.localizedStringWithFormat(Localization.buttonWithActiveFilters, numberOfFilters)
5656

5757
filterButton.setTitle(title, for: .normal)
58-
filterButton.contentEdgeInsets = .zero
58+
var configuration = UIButton.Configuration.filled()
59+
configuration.contentInsets = .init(.zero)
5960
filterButton.accessibilityIdentifier = "orders-filter-button"
6061
}
6162

WooCommerce/Classes/ViewRelated/ReusableViews/EmptyStateViewController/EmptyStateViewController.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,8 @@ private extension EmptyStateViewController {
307307
case .withSupportRequest(_, _, _, let buttonTitle, _):
308308
actionButton.isHidden = false
309309
actionButton.applyLinkButtonStyle()
310-
actionButton.contentEdgeInsets = .zero
310+
var configuration = UIButton.Configuration.filled()
311+
configuration.contentInsets = .init(.zero)
311312
actionButton.setTitle(buttonTitle, for: .normal)
312313
}
313314
}

WooCommerce/Classes/ViewRelated/ReusableViews/VerticalButton.swift

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ class VerticalButton: UIButton {
1010

1111
override func awakeFromNib() {
1212
super.awakeFromNib()
13-
14-
contentEdgeInsets = Settings.edgeInsets
15-
layer.cornerRadius = Settings.cornerRadius
16-
titleLabel?.font = UIFont.footnote
13+
configureButton()
1714
}
1815

1916
override func layoutSubviews() {
@@ -42,6 +39,18 @@ class VerticalButton: UIButton {
4239
width: titleSize.width,
4340
height: titleSize.height).integral
4441
}
42+
43+
private func configureButton() {
44+
var configuration = UIButton.Configuration.filled()
45+
configuration.contentInsets = .init(
46+
top: .zero,
47+
leading: Settings.inset,
48+
bottom: .zero,
49+
trailing: Settings.inset
50+
)
51+
layer.cornerRadius = Settings.cornerRadius
52+
titleLabel?.font = UIFont.footnote
53+
}
4554
}
4655

4756

@@ -51,7 +60,7 @@ private extension VerticalButton {
5160

5261
enum Settings {
5362
static let cornerRadius = CGFloat(10)
54-
static let edgeInsets = UIEdgeInsets(top: 5, left: 0, bottom: 5, right: 0)
63+
static let inset = CGFloat(5)
5564
static let labelPaddingTop = CGFloat(2)
5665
}
5766
}

WooCommerce/Classes/ViewRelated/Survey/SurveySubmittedViewController.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ private extension SurveySubmittedViewController {
9393

9494
contactUsButton.applyLinkButtonStyle()
9595
contactUsButton.titleLabel?.applyCalloutStyle()
96-
contactUsButton.contentEdgeInsets = .zero
96+
var contactUsConfiguration = UIButton.Configuration.plain()
97+
contactUsConfiguration.contentInsets = .init(.zero)
98+
contactUsButton.configuration = contactUsConfiguration
9799
}
98100

99101
/// Apply the correspondent localized texts to each component

0 commit comments

Comments
 (0)