diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2023-04-28 13:55:24 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2023-04-28 13:55:24 +0200 |
| commit | 36963a8eb219489740d34b57d2fb6901b265496d (patch) | |
| tree | 6f618e9d1d922ed896f7894a56a2fcf67030471d | |
| parent | bc1f1642ec674e62a4cf702811babcd78c118ca8 (diff) | |
| parent | 5721afcd758de07c7afd59f53cfe90cdcaaf1a67 (diff) | |
| download | mullvadvpn-36963a8eb219489740d34b57d2fb6901b265496d.tar.xz mullvadvpn-36963a8eb219489740d34b57d2fb6901b265496d.zip | |
Merge branch 'fix-in-app-notification-action-button'
5 files changed, 19 insertions, 17 deletions
diff --git a/ios/MullvadVPN/Notifications/InAppNotificationDescriptor.swift b/ios/MullvadVPN/Notifications/InAppNotificationDescriptor.swift index 63bc9810e3..f2af95365b 100644 --- a/ios/MullvadVPN/Notifications/InAppNotificationDescriptor.swift +++ b/ios/MullvadVPN/Notifications/InAppNotificationDescriptor.swift @@ -10,7 +10,7 @@ import Foundation import UIKit.UIImage /// Struct describing in-app notification. -struct InAppNotificationDescriptor { +struct InAppNotificationDescriptor: Equatable { /// Notification identifier. var identifier: String @@ -23,19 +23,21 @@ struct InAppNotificationDescriptor { /// Notification body. var body: NSAttributedString - /// Notification action + /// Notification action. var action: InAppNotificationAction? } -extension InAppNotificationDescriptor: Equatable { - static func == (lhs: InAppNotificationDescriptor, rhs: InAppNotificationDescriptor) -> Bool { - lhs.identifier == rhs.identifier - } -} - -struct InAppNotificationAction { +/// Type describing a specific in-app notification action. +struct InAppNotificationAction: Equatable { + /// Image assigned to action button. var image: UIImage? + + /// Action handler for button. var handler: (() -> Void)? + + static func == (lhs: InAppNotificationAction, rhs: InAppNotificationAction) -> Bool { + return lhs.image == rhs.image + } } enum NotificationBannerStyle { diff --git a/ios/MullvadVPN/Notifications/NotificationManager.swift b/ios/MullvadVPN/Notifications/NotificationManager.swift index f129fc56ce..6536ae09fc 100644 --- a/ios/MullvadVPN/Notifications/NotificationManager.swift +++ b/ios/MullvadVPN/Notifications/NotificationManager.swift @@ -204,9 +204,7 @@ final class NotificationManager: NotificationProviderDelegate { if let replaceNotificationDescriptor = notificationProvider.notificationDescriptor { newNotificationDescriptors = notificationProviders .compactMap { notificationProvider -> InAppNotificationDescriptor? in - if replaceNotificationDescriptor.identifier == notificationProvider - .identifier - { + if replaceNotificationDescriptor.identifier == notificationProvider.identifier { return replaceNotificationDescriptor } else { return inAppNotificationDescriptors.first { descriptor in diff --git a/ios/MullvadVPN/Notifications/UI/NotificationBannerView.swift b/ios/MullvadVPN/Notifications/UI/NotificationBannerView.swift index 53020f48c6..8cb974b244 100644 --- a/ios/MullvadVPN/Notifications/UI/NotificationBannerView.swift +++ b/ios/MullvadVPN/Notifications/UI/NotificationBannerView.swift @@ -64,7 +64,8 @@ final class NotificationBannerView: UIView { }() private let actionButton: UIButton = { - let button = UIButton() + let button = UIButton(type: .system) + button.tintColor = UIColor.InAppNotificationBanner.actionButtonColor button.translatesAutoresizingMaskIntoConstraints = false return button }() @@ -87,9 +88,9 @@ final class NotificationBannerView: UIView { } } - var actionHandler: InAppNotificationAction? { + var action: InAppNotificationAction? { didSet { - actionButton.setImage(actionHandler?.image, for: .normal) + actionButton.setImage(action?.image, for: .normal) actionButton.addTarget(self, action: #selector(didPress), for: .touchUpInside) } } @@ -148,7 +149,7 @@ final class NotificationBannerView: UIView { } @objc private func didPress() { - actionHandler?.handler?() + action?.handler?() } } diff --git a/ios/MullvadVPN/Notifications/UI/NotificationController.swift b/ios/MullvadVPN/Notifications/UI/NotificationController.swift index 888c4ef497..4825fa689b 100644 --- a/ios/MullvadVPN/Notifications/UI/NotificationController.swift +++ b/ios/MullvadVPN/Notifications/UI/NotificationController.swift @@ -105,7 +105,7 @@ final class NotificationController: UIViewController { bannerView.title = notification.title bannerView.body = notification.body bannerView.style = notification.style - bannerView.actionHandler = notification.action + bannerView.action = notification.action bannerView.accessibilityLabel = "\(notification.title)\n\(notification.body.string)" if animated { diff --git a/ios/MullvadVPN/UI appearance/UIColor+Palette.swift b/ios/MullvadVPN/UI appearance/UIColor+Palette.swift index de2472680a..aff21edac2 100644 --- a/ios/MullvadVPN/UI appearance/UIColor+Palette.swift +++ b/ios/MullvadVPN/UI appearance/UIColor+Palette.swift @@ -118,6 +118,7 @@ extension UIColor { static let titleColor = UIColor.white static let bodyColor = UIColor(white: 1.0, alpha: 0.6) + static let actionButtonColor = UIColor(white: 1.0, alpha: 0.6) } // Common colors |
