diff options
| author | Jon Petersson <jon.petersson@kvadrat.se> | 2023-08-23 15:38:12 +0200 |
|---|---|---|
| committer | Bug Magnet <marco.nikic@mullvad.net> | 2023-09-20 09:22:03 +0200 |
| commit | e2ce740995aaf7175852475daba1fd73c0a54a0d (patch) | |
| tree | 0784921b122a1dc4fefb6cf96609abb944defe2d | |
| parent | 72419399e916783862aad86749214b596509cc02 (diff) | |
| download | mullvadvpn-e2ce740995aaf7175852475daba1fd73c0a54a0d.tar.xz mullvadvpn-e2ce740995aaf7175852475daba1fd73c0a54a0d.zip | |
Coordinate alert presentation by integrating it into routing system
| -rw-r--r-- | ios/MullvadVPN/Coordinators/AccountCoordinator.swift | 1 | ||||
| -rw-r--r-- | ios/MullvadVPN/Coordinators/ApplicationCoordinator.swift | 7 | ||||
| -rw-r--r-- | ios/MullvadVPN/Operations/PresentAlertOperation.swift | 59 |
3 files changed, 66 insertions, 1 deletions
diff --git a/ios/MullvadVPN/Coordinators/AccountCoordinator.swift b/ios/MullvadVPN/Coordinators/AccountCoordinator.swift index 0338d7427b..4202a0076c 100644 --- a/ios/MullvadVPN/Coordinators/AccountCoordinator.swift +++ b/ios/MullvadVPN/Coordinators/AccountCoordinator.swift @@ -136,7 +136,6 @@ final class AccountCoordinator: Coordinator, Presentable, Presenting { let presentation = AlertPresentation( id: "account-logout-alert", icon: .spinner, - message: nil, buttons: [] ) diff --git a/ios/MullvadVPN/Coordinators/ApplicationCoordinator.swift b/ios/MullvadVPN/Coordinators/ApplicationCoordinator.swift index 7f6cb1d474..e6ede7a06c 100644 --- a/ios/MullvadVPN/Coordinators/ApplicationCoordinator.swift +++ b/ios/MullvadVPN/Coordinators/ApplicationCoordinator.swift @@ -1008,3 +1008,10 @@ fileprivate extension AppPreferencesDataSource { // swiftlint:disable:next file_length } + +private protocol Poppable: Presentable { + func popFromNavigationStack( + animated: Bool, + completion: () -> Void + ) +} diff --git a/ios/MullvadVPN/Operations/PresentAlertOperation.swift b/ios/MullvadVPN/Operations/PresentAlertOperation.swift new file mode 100644 index 0000000000..cd6f5b02c2 --- /dev/null +++ b/ios/MullvadVPN/Operations/PresentAlertOperation.swift @@ -0,0 +1,59 @@ +// +// PresentAlertOperation.swift +// MullvadVPN +// +// Created by pronebird on 06/09/2021. +// Copyright © 2021 Mullvad VPN AB. All rights reserved. +// + +import Operations +import UIKit + +final class PresentAlertOperation: AsyncOperation { + private let alertController: AlertViewController + private let presentingController: UIViewController + private let presentCompletion: (() -> Void)? + + init( + alertController: AlertViewController, + presentingController: UIViewController, + presentCompletion: (() -> Void)? = nil + ) { + self.alertController = alertController + self.presentingController = presentingController + self.presentCompletion = presentCompletion + + super.init(dispatchQueue: .main) + } + + override func operationDidCancel() { + // Guard against trying to dismiss the alert when operation hasn't started yet. + guard isExecuting else { return } + + // Guard against dismissing controller during transition. + if !alertController.isBeingPresented, !alertController.isBeingDismissed { + dismissAndFinish() + } + } + + override func main() { + alertController.didDismiss = { [weak self] in + self?.finish() + } + + presentingController.present(alertController, animated: true) { + self.presentCompletion?() + + // Alert operation was cancelled during transition? + if self.isCancelled { + self.dismissAndFinish() + } + } + } + + private func dismissAndFinish() { + alertController.dismiss(animated: false) { + self.finish() + } + } +} |
