diff --git a/ios/MullvadVPN/Coordinators/AccountCoordinator.swift b/ios/MullvadVPN/Coordinators/AccountCoordinator.swift index 0338d7427bf1..3c58e3528740 100644 --- a/ios/MullvadVPN/Coordinators/AccountCoordinator.swift +++ b/ios/MullvadVPN/Coordinators/AccountCoordinator.swift @@ -172,6 +172,7 @@ final class AccountCoordinator: Coordinator, Presentable, Presenting { let presentation = AlertPresentation( id: "account-device-info-alert", + icon: .info, message: message, buttons: [AlertAction( title: NSLocalizedString( diff --git a/ios/MullvadVPN/Coordinators/AlertCoordinator.swift b/ios/MullvadVPN/Coordinators/AlertCoordinator.swift index c06691e22230..f40b9198cc87 100644 --- a/ios/MullvadVPN/Coordinators/AlertCoordinator.swift +++ b/ios/MullvadVPN/Coordinators/AlertCoordinator.swift @@ -25,26 +25,10 @@ final class AlertCoordinator: Coordinator, Presentable { } func start() { - let alertController = AlertViewController( - header: presentation.header, - title: presentation.title, - message: presentation.message, - icon: presentation.icon - ) + alertController = AlertViewController(presentation: presentation) - self.alertController = alertController - - alertController.onDismiss = { [weak self] in + alertController?.onDismiss = { [weak self] in self?.didFinish?() } - - presentation.buttons.forEach { action in - alertController.addAction( - title: action.title, - style: action.style, - accessibilityId: action.accessibilityID, - handler: action.handler - ) - } } } diff --git a/ios/MullvadVPN/Coordinators/ChangeLogCoordinator.swift b/ios/MullvadVPN/Coordinators/ChangeLogCoordinator.swift index e55a31b13db7..915502fd43f7 100644 --- a/ios/MullvadVPN/Coordinators/ChangeLogCoordinator.swift +++ b/ios/MullvadVPN/Coordinators/ChangeLogCoordinator.swift @@ -24,27 +24,28 @@ final class ChangeLogCoordinator: Coordinator, Presentable { } func start() { - let alertController = AlertViewController( + let presentation = AlertPresentation( + id: "change-log-ok-alert", header: interactor.viewModel.header, title: interactor.viewModel.title, - attributedMessage: interactor.viewModel.body + attributedMessage: interactor.viewModel.body, + buttons: [ + AlertAction( + title: NSLocalizedString( + "CHANGE_LOG_OK_ACTION", + tableName: "Account", + value: "Got it!", + comment: "" + ), + style: .default, + handler: { [weak self] in + guard let self else { return } + didFinish?(self) + } + ), + ] ) - alertController.addAction( - title: NSLocalizedString( - "CHANGE_LOG_OK_ACTION", - tableName: "Account", - value: "Got it!", - comment: "" - ), - style: .default, - accessibilityId: "OkButton", - handler: { [weak self] in - guard let self else { return } - didFinish?(self) - } - ) - - self.alertController = alertController + alertController = AlertViewController(presentation: presentation) } } diff --git a/ios/MullvadVPN/View controllers/Alert/AlertPresentation.swift b/ios/MullvadVPN/View controllers/Alert/AlertPresentation.swift index c09d0e1e72e5..38f60a8981d4 100644 --- a/ios/MullvadVPN/View controllers/Alert/AlertPresentation.swift +++ b/ios/MullvadVPN/View controllers/Alert/AlertPresentation.swift @@ -27,7 +27,8 @@ struct AlertPresentation: Identifiable, CustomDebugStringConvertible { var header: String? var icon: AlertIcon? var title: String? - let message: String? + var message: String? + var attributedMessage: NSAttributedString? let buttons: [AlertAction] var debugDescription: String { diff --git a/ios/MullvadVPN/View controllers/Alert/AlertViewController.swift b/ios/MullvadVPN/View controllers/Alert/AlertViewController.swift index bac96175b2a8..d45e16bcf668 100644 --- a/ios/MullvadVPN/View controllers/Alert/AlertViewController.swift +++ b/ios/MullvadVPN/View controllers/Alert/AlertViewController.swift @@ -58,19 +58,27 @@ class AlertViewController: UIViewController { private var handlers = [UIButton: Handler]() - init(header: String? = nil, title: String? = nil, message: String? = nil, icon: AlertIcon? = nil) { + init(presentation: AlertPresentation) { super.init(nibName: nil, bundle: nil) - setUp(header: header, title: title, icon: icon) { - message.flatMap { addMessage($0) } + setUp( + header: presentation.header, + title: presentation.title, + icon: presentation.icon + ) { + if let message = presentation.attributedMessage { + addMessage(message) + } else if let message = presentation.message { + addMessage(message) + } } - } - - init(header: String? = nil, title: String? = nil, attributedMessage: NSAttributedString?, icon: AlertIcon? = nil) { - super.init(nibName: nil, bundle: nil) - setUp(header: header, title: title, icon: icon) { - attributedMessage.flatMap { addMessage($0) } + presentation.buttons.forEach { action in + addAction( + title: action.title, + style: action.style, + handler: action.handler + ) } } @@ -120,14 +128,13 @@ class AlertViewController: UIViewController { } } - func addAction(title: String, style: AlertActionStyle, accessibilityId: String?, handler: (() -> Void)? = nil) { + func addAction(title: String, style: AlertActionStyle, handler: (() -> Void)? = nil) { // The presence of a button should reset any custom button margin to default. containerView.directionalLayoutMargins.bottom = UIMetrics.CustomAlert.containerMargins.bottom let button = AppButton(style: style.buttonStyle) button.setTitle(title, for: .normal) - button.accessibilityIdentifier = accessibilityId button.addTarget(self, action: #selector(didTapButton), for: .touchUpInside) containerView.addArrangedSubview(button) @@ -185,6 +192,7 @@ class AlertViewController: UIViewController { let label = UILabel() label.attributedText = message + label.textColor = .white.withAlphaComponent(0.8) label.adjustsFontForContentSizeCategory = true label.numberOfLines = 0 diff --git a/ios/MullvadVPN/View controllers/DeviceList/DeviceManagementViewController.swift b/ios/MullvadVPN/View controllers/DeviceList/DeviceManagementViewController.swift index 7675490333c2..887eb62c20c5 100644 --- a/ios/MullvadVPN/View controllers/DeviceList/DeviceManagementViewController.swift +++ b/ios/MullvadVPN/View controllers/DeviceList/DeviceManagementViewController.swift @@ -183,17 +183,26 @@ class DeviceManagementViewController: UIViewController, RootContainment { deviceName: String, completion: @escaping (_ shouldDelete: Bool) -> Void ) { + let text = String( + format: NSLocalizedString( + "DELETE_ALERT_TITLE", + tableName: "DeviceManagement", + value: "Are you sure you want to log **\(deviceName)** out?", + comment: "" + ) + ) + + let attributedText = NSAttributedString( + markdownString: text, + options: MarkdownStylingOptions( + font: .preferredFont(forTextStyle: .body) + ) + ) + let presentation = AlertPresentation( id: "logout-confirmation-alert", icon: .alert, - message: String( - format: NSLocalizedString( - "DELETE_ALERT_TITLE", - tableName: "DeviceManagement", - value: "Are you sure you want to log %@ out?", - comment: "" - ), deviceName - ), + attributedMessage: attributedText, buttons: [ AlertAction( title: NSLocalizedString( diff --git a/ios/MullvadVPNScreenshots/MullvadVPNScreenshots.swift b/ios/MullvadVPNScreenshots/MullvadVPNScreenshots.swift index 0e050b872ddc..56e6f5e4faad 100644 --- a/ios/MullvadVPNScreenshots/MullvadVPNScreenshots.swift +++ b/ios/MullvadVPNScreenshots/MullvadVPNScreenshots.swift @@ -39,8 +39,8 @@ class MullvadVPNScreenshots: XCTestCase { app.buttons["AgreeButton"].tap() // Dismiss changelog screen - _ = app.buttons["OkButton"].waitForExistence(timeout: 10) - app.buttons["OkButton"].tap() + _ = app.buttons["Got it!"].waitForExistence(timeout: 10) + app.buttons["Got it!"].tap() // Wait for Login screen let textField = app.textFields["LoginTextField"]