diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2023-05-25 16:48:20 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2023-05-30 11:17:30 +0200 |
| commit | e06aacee9366c0620243d34c4e92f68714240768 (patch) | |
| tree | b9647f0f996b95c0feb9a0a64117bf387617cb08 | |
| parent | 195947c4b44d6033d6f15d78a1c8a39c24855bd9 (diff) | |
| download | mullvadvpn-e06aacee9366c0620243d34c4e92f68714240768.tar.xz mullvadvpn-e06aacee9366c0620243d34c4e92f68714240768.zip | |
NotificationBanner: break down init() on smaller functions
| -rw-r--r-- | ios/MullvadVPN/Notifications/UI/NotificationBannerView.swift | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/ios/MullvadVPN/Notifications/UI/NotificationBannerView.swift b/ios/MullvadVPN/Notifications/UI/NotificationBannerView.swift index 04177463db..dc2055765b 100644 --- a/ios/MullvadVPN/Notifications/UI/NotificationBannerView.swift +++ b/ios/MullvadVPN/Notifications/UI/NotificationBannerView.swift @@ -51,8 +51,8 @@ final class NotificationBannerView: UIView { return view }() - private let bodyStackView: UIStackView = { - let stackView = UIStackView() + private lazy var bodyStackView: UIStackView = { + let stackView = UIStackView(arrangedSubviews: [bodyLabel, actionButton]) stackView.alignment = .top stackView.distribution = .fill stackView.spacing = UIStackView.spacingUseSystem @@ -96,13 +96,20 @@ final class NotificationBannerView: UIView { override init(frame: CGRect) { super.init(frame: frame) - actionButton.addTarget(self, action: #selector(handleActionTap), for: .touchUpInside) + addActionHandlers() + addSubviews() + addConstraints() + } - actionButton.setContentCompressionResistancePriority(.defaultHigh + 1, for: .horizontal) - actionButton.setContentCompressionResistancePriority(.defaultHigh + 1, for: .vertical) - actionButton.setContentHuggingPriority(.defaultHigh + 1, for: .horizontal) - actionButton.setContentHuggingPriority(.defaultHigh + 1, for: .vertical) + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + private func addActionHandlers() { + actionButton.addTarget(self, action: #selector(handleActionTap), for: .touchUpInside) + } + + private func addSubviews() { wrapperView.addConstrainedSubviews([titleLabel, indicatorView, bodyStackView]) backgroundView.contentView.addConstrainedSubviews([wrapperView]) { wrapperView.pinEdgesToSuperview() @@ -110,9 +117,14 @@ final class NotificationBannerView: UIView { addConstrainedSubviews([backgroundView]) { backgroundView.pinEdgesToSuperview() } + } - bodyStackView.addArrangedSubview(bodyLabel) - bodyStackView.addArrangedSubview(actionButton) + private func addConstraints() { + let actionButtonPriority: UILayoutPriority = .defaultHigh + 1 + actionButton.setContentCompressionResistancePriority(actionButtonPriority, for: .horizontal) + actionButton.setContentCompressionResistancePriority(actionButtonPriority, for: .vertical) + actionButton.setContentHuggingPriority(actionButtonPriority, for: .horizontal) + actionButton.setContentHuggingPriority(actionButtonPriority, for: .vertical) NSLayoutConstraint.activate([ indicatorView.bottomAnchor.constraint(equalTo: titleLabel.firstBaselineAnchor), @@ -133,10 +145,6 @@ final class NotificationBannerView: UIView { ]) } - required init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - @objc private func handleActionTap() { action?.handler?() } |
