Skip to content

Commit da17537

Browse files
improve the way of adding primary and secondary buttons in UKAlert
1 parent dacbe5c commit da17537

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

Sources/ComponentsKit/Components/Alert/Models/AlertVM.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,12 @@ extension AlertVM {
6666
}
6767

6868
var primaryButtonVM: ButtonVM? {
69-
return self.primaryButton.map(self.mapAlertButtonVM)
69+
let buttonVM = self.primaryButton.map(self.mapAlertButtonVM)
70+
if self.secondaryButton.isNotNil {
71+
return buttonVM
72+
} else {
73+
return buttonVM ?? Self.defaultButtonVM
74+
}
7075
}
7176

7277
var secondaryButtonVM: ButtonVM? {

Sources/ComponentsKit/Components/Alert/UKAlertController.swift

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,11 @@ public class UKAlertController: UKCenterModalController {
9191
}
9292
self.footer = self.buttonsStackView
9393

94-
switch (self.alertVM.primaryButton.isNotNil, self.alertVM.secondaryButton.isNotNil) {
95-
case (true, true):
94+
if self.alertVM.primaryButtonVM.isNotNil {
9695
self.buttonsStackView.addArrangedSubview(self.primaryButton)
96+
}
97+
if self.alertVM.secondaryButtonVM.isNotNil {
9798
self.buttonsStackView.addArrangedSubview(self.secondaryButton)
98-
case (false, true):
99-
self.buttonsStackView.addArrangedSubview(self.secondaryButton)
100-
case (_, false):
101-
self.buttonsStackView.addArrangedSubview(self.primaryButton)
10299
}
103100

104101
self.primaryButton.action = { [weak self] in
@@ -128,7 +125,6 @@ public class UKAlertController: UKCenterModalController {
128125
if let primaryButtonVM = self.alertVM.primaryButtonVM {
129126
self.primaryButton.model = primaryButtonVM
130127
}
131-
self.primaryButton.model = self.alertVM.primaryButtonVM ?? AlertVM.defaultButtonVM
132128
if let secondaryButtonVM = self.alertVM.secondaryButtonVM {
133129
self.secondaryButton.model = secondaryButtonVM
134130
}

0 commit comments

Comments
 (0)