diff options
Diffstat (limited to 'ios/MullvadVPN/Notifications/UI')
| -rw-r--r-- | ios/MullvadVPN/Notifications/UI/NotificationBannerView.swift | 45 | ||||
| -rw-r--r-- | ios/MullvadVPN/Notifications/UI/NotificationController.swift | 3 |
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 |
