Skip to content

Commit fa7e694

Browse files
committed
Add custom spacing for modals without buttons on iPad
1 parent c947148 commit fa7e694

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

WooCommerce/Classes/ViewRelated/CardPresentPayments/CardPresentPaymentsModalViewController.swift

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ final class CardPresentPaymentsModalViewController: UIViewController {
1111

1212
@IBOutlet weak var containerView: UIView!
1313
@IBOutlet weak var mainStackView: UIStackView!
14+
@IBOutlet weak var bottomPaddingRegular: NSLayoutConstraint!
1415
@IBOutlet weak var primaryActionButtonsStackView: UIStackView!
1516
@IBOutlet weak var buttonsSpacer: UIView!
1617
@IBOutlet private weak var topTitleLabel: UILabel!
@@ -82,6 +83,7 @@ final class CardPresentPaymentsModalViewController: UIViewController {
8283

8384
heightConstraint.priority = .required
8485
widthConstraint.priority = .required
86+
configureSpacer()
8587
}
8688
}
8789

@@ -117,8 +119,8 @@ private extension CardPresentPaymentsModalViewController {
117119

118120
func styleBottomLabels() {
119121
actionButtonsView.isHidden = true
120-
buttonsSpacer.isHidden = false
121122
bottomLabels.isHidden = false
123+
configureSpacer()
122124

123125
styleBottomTitle()
124126
styleBottomSubtitle()
@@ -134,8 +136,8 @@ private extension CardPresentPaymentsModalViewController {
134136

135137
func styleActionButtons() {
136138
actionButtonsView.isHidden = false
137-
buttonsSpacer.isHidden = true
138139
bottomLabels.isHidden = true
140+
configureSpacer()
139141

140142
stylePrimaryButton()
141143
styleSecondaryButton()
@@ -239,7 +241,7 @@ private extension CardPresentPaymentsModalViewController {
239241

240242
func hideActionButtonsView() {
241243
actionButtonsView.isHidden = true
242-
buttonsSpacer.isHidden = false
244+
configureSpacer()
243245
}
244246

245247
func configurePrimaryButton() {
@@ -271,6 +273,30 @@ private extension CardPresentPaymentsModalViewController {
271273
auxiliaryButton.isHidden = false
272274
auxiliaryButton.setTitle(viewModel.auxiliaryButtonTitle, for: .normal)
273275
}
276+
277+
func configureSpacer() {
278+
let enabled = !shouldShowActionButtons()
279+
280+
if isRegularClassSize {
281+
buttonsSpacer.isHidden = true
282+
// For iPads, instead of a flexible spacer we expand the bottom margin with an extra 127px.
283+
// This would be the space equivalents to the primary and secondary buttons being visible
284+
// - 32px of spacing between buttons container and the rest of the content
285+
// - 40px for the primary button
286+
// - 15px of spacing between buttons
287+
// - 40px for the secondary button
288+
bottomPaddingRegular.constant = 42 + (enabled ? 127 : 0)
289+
} else {
290+
// For compact screens (iPhones, or iPad in split mode), we us a flexible spacer with a low
291+
// content hugging priority to ensure it takes all the available space, leaving the rest of
292+
// the visible items aligned to the top of the stack view
293+
buttonsSpacer.isHidden = !enabled
294+
}
295+
}
296+
297+
var isRegularClassSize: Bool {
298+
traitCollection.verticalSizeClass == .regular && traitCollection.horizontalSizeClass == .regular
299+
}
274300
}
275301

276302
// MARK: - View layout configuration

WooCommerce/Classes/ViewRelated/CardPresentPayments/CardPresentPaymentsModalViewController.xib

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<outlet property="actionButtonsView" destination="10Z-y1-ZQ6" id="L1z-Zs-L2J"/>
1414
<outlet property="auxiliaryButton" destination="maO-19-PuQ" id="cQA-7p-jmo"/>
1515
<outlet property="bottomLabels" destination="k73-qi-GuD" id="LvQ-UE-SBc"/>
16+
<outlet property="bottomPaddingRegular" destination="lVZ-pu-Fmb" id="CJM-oy-oSx"/>
1617
<outlet property="bottomSubtitleLabel" destination="2Sx-5s-f7J" id="Mco-Vu-Li6"/>
1718
<outlet property="bottomTitleLabel" destination="oAj-lv-0k9" id="Clc-oi-Ywf"/>
1819
<outlet property="buttonsSpacer" destination="OFI-6w-cag" id="Uva-gQ-T7X"/>

0 commit comments

Comments
 (0)