Skip to content

Commit 8f931b9

Browse files
committed
Fix button with loading not resizing
1 parent 39b7237 commit 8f931b9

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

Demo/Pins/Components/PinButton.swift

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class PinButton: View {
99
var secondary: Button!
1010
var tertiary: Button!
1111
var custom: Button!
12+
var primaryFloating: Button!
1213

1314
override func setup() {
1415
primary = Button(title: "Press me")
@@ -42,6 +43,8 @@ class PinButton: View {
4243
let customDisabled = Button(title: "Custom", font: .caption, style: .custom(textColor: .green, backgroundColor: .red))
4344
customDisabled.isEnabled = false
4445

46+
primaryFloating = Button(title: "Continue")
47+
4548
let stackView = UIStackView(axis: .vertical, spacing: .spacingM, alignment: .center)
4649
stackView.addArrangedSubviews([
4750
primary,
@@ -58,6 +61,13 @@ class PinButton: View {
5861
])
5962
addSubview(stackView)
6063
stackView.anchorToTopSafeArea(margin: .spacingXXL)
64+
65+
addSubview(primaryFloating)
66+
NSLayoutConstraint.activate([
67+
primaryFloating.leadingAnchor.constraint(greaterThanOrEqualTo: leadingAnchor, constant: .spacingM),
68+
primaryFloating.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -.spacingM),
69+
primaryFloating.bottomAnchor.constraint(equalTo: safeAreaLayoutGuide.bottomAnchor, constant: -.spacingM)
70+
])
6171
}
6272

6373
@objc func loadingPressed(_ button: Button) {
@@ -83,7 +93,8 @@ class PinButton: View {
8393
}
8494

8595
@objc func loading() {
86-
primaryLoading.title = primaryLoading.isLoading ? "Save" : "Saving"
87-
primaryLoading.showActivityIndicator(!primaryLoading.isLoading)
96+
// primaryLoading.title = primaryLoading.isLoading ? "Save" : "Saving"
97+
// primaryLoading.showActivityIndicator(!primaryLoading.isLoading)
98+
primaryFloating.showActivityIndicator(!primaryFloating.isLoading)
8899
}
89100
}

Pinwheel/Sources/Pinwheel/Components/Button.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ public class Button: UIButton {
142142

143143
let value = -activityIndicator.bounds.width / 2 - .spacingXS
144144
titleLabelCenterXConstraint?.constant = value
145+
146+
invalidateIntrinsicContentSize()
145147
} else {
146148
subviews.forEach {
147149
if let activityIndicator = $0 as? UIActivityIndicatorView {
@@ -151,6 +153,8 @@ public class Button: UIButton {
151153
titleLabelCenterXConstraint?.constant = 0
152154

153155
self.layoutIfNeeded()
156+
157+
invalidateIntrinsicContentSize()
154158
}
155159
}
156160

0 commit comments

Comments
 (0)