@@ -22,6 +22,8 @@ final class AlertView: UIView {
2222
2323 // MARK: - Subviews
2424
25+ // MARK: Blur
26+
2527 private lazy var blurView : UIVisualEffectView = {
2628 let blurEffect = UIBlurEffect ( style: . extraLight)
2729
@@ -32,14 +34,16 @@ final class AlertView: UIView {
3234 return effectView
3335 } ( )
3436
37+ // MARK: Content
38+
3539 private lazy var contentContainerView : UIView = {
3640 let containerView = UIView ( )
3741 containerView. translatesAutoresizingMaskIntoConstraints = false
3842 blurView. contentView. addSubview ( containerView)
3943 return containerView
4044 } ( )
4145
42- private lazy var verticalStackView : UIStackView = {
46+ private lazy var contentStackView : UIStackView = {
4347 let stackView = UIStackView ( )
4448 stackView. translatesAutoresizingMaskIntoConstraints = false
4549 contentContainerView. addSubview ( stackView)
@@ -66,19 +70,26 @@ final class AlertView: UIView {
6670 return contentView
6771 } ( )
6872
73+ // MARK: Actions
74+
75+ private lazy var actionsStackView : UIStackView = {
76+ let stackView = UIStackView ( )
77+ stackView. translatesAutoresizingMaskIntoConstraints = false
78+ blurView. contentView. addSubview ( stackView)
79+ return stackView
80+ } ( )
81+
6982 private lazy var contentSeparatorView : UIView = {
7083 let separatorView = UIView ( )
7184 separatorView. backgroundColor = separatorColor
7285 separatorView. translatesAutoresizingMaskIntoConstraints = false
73- blurView. contentView. addSubview ( separatorView)
7486 return separatorView
7587 } ( )
7688
77- private lazy var actionsContainerView : AlertActionSequenceView = {
78- let containerView = AlertActionSequenceView ( )
79- containerView. translatesAutoresizingMaskIntoConstraints = false
80- blurView. contentView. addSubview ( containerView)
81- return containerView
89+ private lazy var actionSequenceView : AlertActionSequenceView = {
90+ let sequenceView = AlertActionSequenceView ( )
91+ sequenceView. translatesAutoresizingMaskIntoConstraints = false
92+ return sequenceView
8293 } ( )
8394
8495 // MARK: - Init
@@ -111,35 +122,38 @@ final class AlertView: UIView {
111122 contentContainerView. leadingAnchor. constraint ( equalTo: blurView. contentView. leadingAnchor) ,
112123 contentContainerView. trailingAnchor. constraint ( equalTo: blurView. contentView. trailingAnchor) ,
113124
114- verticalStackView. topAnchor. constraint ( equalTo: contentContainerView. topAnchor, constant: Layout . Content. top) ,
115- verticalStackView. leadingAnchor. constraint ( equalTo: contentContainerView. leadingAnchor, constant: Layout . Content. horizontal) ,
116- verticalStackView. trailingAnchor. constraint ( equalTo: contentContainerView. trailingAnchor, constant: - Layout. Content. horizontal) ,
117- verticalStackView. bottomAnchor. constraint ( equalTo: contentContainerView. bottomAnchor, constant: - Layout. Content. bottom) ,
118-
119- contentSeparatorView. topAnchor. constraint ( equalTo: contentContainerView. bottomAnchor) ,
120- contentSeparatorView. leadingAnchor. constraint ( equalTo: blurView. contentView. leadingAnchor) ,
121- contentSeparatorView. trailingAnchor. constraint ( equalTo: blurView. contentView. trailingAnchor) ,
122- contentSeparatorView. heightAnchor. constraint ( equalToConstant: Layout . separatorThickness) ,
125+ contentStackView. topAnchor. constraint ( equalTo: contentContainerView. topAnchor, constant: Layout . Content. top) ,
126+ contentStackView. leadingAnchor. constraint ( equalTo: contentContainerView. leadingAnchor, constant: Layout . Content. horizontal) ,
127+ contentStackView. trailingAnchor. constraint ( equalTo: contentContainerView. trailingAnchor, constant: - Layout. Content. horizontal) ,
128+ contentStackView. bottomAnchor. constraint ( equalTo: contentContainerView. bottomAnchor, constant: - Layout. Content. bottom) ,
123129
124- actionsContainerView. topAnchor. constraint ( equalTo: contentSeparatorView. bottomAnchor) ,
125- actionsContainerView. leadingAnchor. constraint ( equalTo: blurView. contentView. leadingAnchor) ,
126- actionsContainerView. trailingAnchor. constraint ( equalTo: blurView. contentView. trailingAnchor) ,
127- actionsContainerView. bottomAnchor. constraint ( equalTo: blurView. contentView. bottomAnchor) ,
128- actionsContainerView. heightAnchor. constraint ( equalToConstant: Layout . Button. height)
130+ actionsStackView. topAnchor. constraint ( equalTo: contentContainerView. bottomAnchor) ,
131+ actionsStackView. leadingAnchor. constraint ( equalTo: blurView. contentView. leadingAnchor) ,
132+ actionsStackView. trailingAnchor. constraint ( equalTo: blurView. contentView. trailingAnchor) ,
133+ actionsStackView. bottomAnchor. constraint ( equalTo: blurView. contentView. bottomAnchor)
129134 ] )
130135
131- verticalStackView. axis = . vertical
132- verticalStackView. spacing = Layout . Content. verticalSpacing
133- verticalStackView. addArrangedSubview ( titleLabel)
134- verticalStackView. addArrangedSubview ( messageLabel)
135- verticalStackView. addArrangedSubview ( customContentView)
136+ contentStackView. axis = . vertical
137+ contentStackView. spacing = Layout . Content. verticalSpacing
138+ contentStackView. addArrangedSubview ( titleLabel)
139+ contentStackView. addArrangedSubview ( messageLabel)
140+ contentStackView. addArrangedSubview ( customContentView)
141+
142+ actionsStackView. axis = . vertical
143+ actionsStackView. spacing = 0
144+ actionsStackView. addArrangedSubview ( contentSeparatorView)
145+ actionsStackView. addArrangedSubview ( actionSequenceView)
146+
147+ NSLayoutConstraint . activate ( [
148+ contentSeparatorView. heightAnchor. constraint ( equalToConstant: Layout . separatorThickness)
149+ ] )
136150
137- titleLabel. setContentHuggingPriority ( . required , for : . vertical )
138- titleLabel . setContentCompressionResistancePriority ( . required, for: . vertical)
139- messageLabel . setContentHuggingPriority ( . required, for: . vertical)
140- messageLabel . setContentCompressionResistancePriority ( . required , for : . vertical )
151+ [ titleLabel, messageLabel ] . forEach {
152+ $0 . setContentHuggingPriority ( . required, for: . vertical)
153+ $0 . setContentCompressionResistancePriority ( . required, for: . vertical)
154+ }
141155
142- actionsContainerView . delegate = self
156+ actionSequenceView . delegate = self
143157 }
144158
145159 private func setupAppearance( ) {
@@ -191,13 +205,17 @@ final class AlertView: UIView {
191205 }
192206 customContentView. isHidden = viewModel. contentView == nil
193207
194- let actionsViewModel = AlertActionSequenceViewModel (
195- actions: viewModel. actions,
196- disabledTintColor: viewModel. disabledTintColor,
197- separatorColor: separatorColor,
198- separatorWidth: Layout . separatorThickness
199- )
200- actionsContainerView. setup ( viewModel: actionsViewModel)
208+ if !viewModel. actions. isEmpty {
209+ let actionsViewModel = AlertActionSequenceViewModel (
210+ actions: viewModel. actions,
211+ disabledTintColor: viewModel. disabledTintColor,
212+ separatorColor: separatorColor,
213+ separatorWidth: Layout . separatorThickness
214+ )
215+ actionSequenceView. setup ( viewModel: actionsViewModel)
216+ }
217+ contentSeparatorView. isHidden = viewModel. actions. isEmpty
218+ actionSequenceView. isHidden = viewModel. actions. isEmpty
201219 }
202220
203221 // MARK: - Layout
@@ -214,10 +232,6 @@ final class AlertView: UIView {
214232 static let horizontal : CGFloat = 16
215233 static let verticalSpacing : CGFloat = 4
216234 }
217-
218- enum Button {
219- static let height : CGFloat = 44
220- }
221235 }
222236}
223237
0 commit comments