diff options
| author | Jon Petersson <jon.petersson@mullvad.net> | 2025-01-22 16:39:21 +0100 |
|---|---|---|
| committer | Jon Petersson <jon.petersson@mullvad.net> | 2025-01-22 16:39:21 +0100 |
| commit | a1b47c23a9532abc0f51fc94de481b0528afb9fb (patch) | |
| tree | 8c93aed3d2fc5540e963bc6b02dbdd8549268429 /ios/MullvadVPN/Notifications/UI/NotificationBannerView.swift | |
| parent | 060839d420a9cf222b49fe4932730a98fd5b1434 (diff) | |
| parent | 5f9315b46dc7a364bc20d40420c2e0feb34a2d6c (diff) | |
| download | mullvadvpn-a1b47c23a9532abc0f51fc94de481b0528afb9fb.tar.xz mullvadvpn-a1b47c23a9532abc0f51fc94de481b0528afb9fb.zip | |
Merge branch 'add-in-app-notification-banner-for-changelog-ios-989'
Diffstat (limited to 'ios/MullvadVPN/Notifications/UI/NotificationBannerView.swift')
| -rw-r--r-- | ios/MullvadVPN/Notifications/UI/NotificationBannerView.swift | 45 |
1 files changed, 30 insertions, 15 deletions
diff --git a/ios/MullvadVPN/Notifications/UI/NotificationBannerView.swift b/ios/MullvadVPN/Notifications/UI/NotificationBannerView.swift index 32449fa59d..7dea419a73 100644 --- a/ios/MullvadVPN/Notifications/UI/NotificationBannerView.swift +++ b/ios/MullvadVPN/Notifications/UI/NotificationBannerView.swift @@ -46,9 +46,16 @@ final class NotificationBannerView: UIView { }() private lazy var bodyStackView: UIStackView = { - let stackView = UIStackView(arrangedSubviews: [bodyLabel, actionButton]) + let stackView = UIStackView(arrangedSubviews: [titleLabel, bodyLabel]) stackView.alignment = .top stackView.distribution = .fill + stackView.axis = .vertical + stackView.spacing = UIStackView.spacingUseSystem + return stackView + }() + + private lazy var contentStackView: UIStackView = { + let stackView = UIStackView(arrangedSubviews: [bodyStackView, actionButton]) stackView.spacing = UIStackView.spacingUseSystem return stackView }() @@ -87,11 +94,13 @@ final class NotificationBannerView: UIView { } } + var tapAction: InAppNotificationAction? + override init(frame: CGRect) { super.init(frame: frame) - - addActionHandlers() addSubviews() + addTapHandler() + addActionHandlers() addConstraints() } @@ -99,12 +108,22 @@ final class NotificationBannerView: UIView { fatalError("init(coder:) has not been implemented") } + private func addTapHandler() { + let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTap)) + addGestureRecognizer(tapGesture) + } + private func addActionHandlers() { actionButton.addTarget(self, action: #selector(handleActionTap), for: .touchUpInside) } + @objc + private func handleTap() { + tapAction?.handler?() + } + private func addSubviews() { - wrapperView.addConstrainedSubviews([titleLabel, indicatorView, bodyStackView]) + wrapperView.addConstrainedSubviews([indicatorView, contentStackView]) backgroundView.contentView.addConstrainedSubviews([wrapperView]) { wrapperView.pinEdgesToSuperview() } @@ -114,9 +133,6 @@ final class NotificationBannerView: UIView { } private func addConstraints() { - actionButton.setContentCompressionResistancePriority(.required, for: .horizontal) - actionButton.setContentHuggingPriority(.required, for: .horizontal) - NSLayoutConstraint.activate([ indicatorView.bottomAnchor.constraint(equalTo: titleLabel.firstBaselineAnchor), indicatorView.leadingAnchor.constraint(equalTo: wrapperView.layoutMarginsGuide.leadingAnchor), @@ -125,14 +141,13 @@ final class NotificationBannerView: UIView { indicatorView.heightAnchor .constraint(equalToConstant: UIMetrics.InAppBannerNotification.indicatorSize.height), - titleLabel.topAnchor.constraint(equalTo: wrapperView.layoutMarginsGuide.topAnchor), - titleLabel.leadingAnchor.constraint(equalToSystemSpacingAfter: indicatorView.trailingAnchor, multiplier: 1), - titleLabel.trailingAnchor.constraint(equalTo: wrapperView.layoutMarginsGuide.trailingAnchor), - - bodyStackView.topAnchor.constraint(equalToSystemSpacingBelow: titleLabel.bottomAnchor, multiplier: 1), - bodyStackView.leadingAnchor.constraint(equalTo: titleLabel.leadingAnchor), - bodyStackView.trailingAnchor.constraint(equalTo: titleLabel.trailingAnchor), - bodyStackView.bottomAnchor.constraint(equalTo: wrapperView.layoutMarginsGuide.bottomAnchor), + contentStackView.topAnchor.constraint(equalTo: wrapperView.layoutMarginsGuide.topAnchor), + contentStackView.leadingAnchor.constraint( + equalToSystemSpacingAfter: indicatorView.trailingAnchor, + multiplier: 1 + ), + contentStackView.trailingAnchor.constraint(equalTo: wrapperView.layoutMarginsGuide.trailingAnchor), + contentStackView.bottomAnchor.constraint(equalTo: wrapperView.layoutMarginsGuide.bottomAnchor), ]) } |
