summaryrefslogtreecommitdiffhomepage
path: root/ios/MullvadVPN/Notifications/UI
diff options
context:
space:
mode:
authorJon Petersson <jon.petersson@mullvad.net>2025-01-22 16:39:21 +0100
committerJon Petersson <jon.petersson@mullvad.net>2025-01-22 16:39:21 +0100
commita1b47c23a9532abc0f51fc94de481b0528afb9fb (patch)
tree8c93aed3d2fc5540e963bc6b02dbdd8549268429 /ios/MullvadVPN/Notifications/UI
parent060839d420a9cf222b49fe4932730a98fd5b1434 (diff)
parent5f9315b46dc7a364bc20d40420c2e0feb34a2d6c (diff)
downloadmullvadvpn-a1b47c23a9532abc0f51fc94de481b0528afb9fb.tar.xz
mullvadvpn-a1b47c23a9532abc0f51fc94de481b0528afb9fb.zip
Merge branch 'add-in-app-notification-banner-for-changelog-ios-989'
Diffstat (limited to 'ios/MullvadVPN/Notifications/UI')
-rw-r--r--ios/MullvadVPN/Notifications/UI/NotificationBannerView.swift45
-rw-r--r--ios/MullvadVPN/Notifications/UI/NotificationController.swift3
2 files changed, 32 insertions, 16 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),
])
}
diff --git a/ios/MullvadVPN/Notifications/UI/NotificationController.swift b/ios/MullvadVPN/Notifications/UI/NotificationController.swift
index b29e3d2bae..f0e9a82e57 100644
--- a/ios/MullvadVPN/Notifications/UI/NotificationController.swift
+++ b/ios/MullvadVPN/Notifications/UI/NotificationController.swift
@@ -97,7 +97,8 @@ final class NotificationController: UIViewController {
bannerView.title = notification.title
bannerView.body = notification.body
bannerView.style = notification.style
- bannerView.action = notification.action
+ bannerView.action = notification.button
+ bannerView.tapAction = notification.tapAction
bannerView.accessibilityLabel = "\(notification.title)\n\(notification.body.string)"
// Do not emit the .layoutChanged unless the banner is focused to avoid capturing