diff --git a/ui/BankingiOSApp/BankingiOSApp/persistence/Extensions.swift b/ui/BankingiOSApp/BankingiOSApp/persistence/Extensions.swift index b1fab28f..1f0cf4df 100644 --- a/ui/BankingiOSApp/BankingiOSApp/persistence/Extensions.swift +++ b/ui/BankingiOSApp/BankingiOSApp/persistence/Extensions.swift @@ -11,27 +11,27 @@ extension AppDelegate { extension SceneDelegate { - public static var currentWindow: UIWindow { + static var currentWindow: UIWindow { UIApplication.shared.windows.first(where: { (window) -> Bool in window.isKeyWindow})! } - public static var currentScene: UIWindowScene { currentWindow.windowScene! } + static var currentScene: UIWindowScene { currentWindow.windowScene! } - public static var current: SceneDelegate { currentScene.delegate as! SceneDelegate } + static var current: SceneDelegate { currentScene.delegate as! SceneDelegate } - public static var rootViewController: UIViewController? { + static var rootViewController: UIViewController? { currentWindow.rootViewController } - public static var rootNavigationController: UINavigationController? { + static var rootNavigationController: UINavigationController? { rootViewController as? UINavigationController } - public static var rootTabBarController: UITabBarController? { + static var rootTabBarController: UITabBarController? { rootNavigationController?.viewControllers.first as? UITabBarController } - public static var currentViewController: UIViewController? { + static var currentViewController: UIViewController? { var currentViewController = rootTabBarController?.selectedViewController ?? rootTabBarController while currentViewController?.presentedViewController != nil { @@ -41,18 +41,22 @@ extension SceneDelegate { return currentViewController } - public static var currentNavigationItem: UINavigationItem? { + static var currentNavigationItem: UINavigationItem? { currentViewController?.navigationItem } - public static func navigateToView(_ view: Content) { + static func navigateToView(_ view: Content) { navigateToViewController(UIHostingController(rootView: view)) } - public static func navigateToViewController(_ viewController: UIViewController) { + static func navigateToViewController(_ viewController: UIViewController) { rootNavigationController?.pushViewController(viewController, animated: true) } + + static func dismissCurrentView() { + rootNavigationController?.popViewController(animated: false) + } } diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/views/AddAccountDialog.swift b/ui/BankingiOSApp/BankingiOSApp/ui/views/AddAccountDialog.swift index 255755c8..4f87ae98 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/views/AddAccountDialog.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/views/AddAccountDialog.swift @@ -5,8 +5,6 @@ import Combine struct AddAccountDialog: View { - @Environment(\.presentationMode) var presentation - @State private var bank: BankInfo? = nil @State private var customerId = "" @@ -102,16 +100,14 @@ struct AddAccountDialog: View { DispatchQueue.main.async { // dispatch async as may EnterTanDialog is still displayed so dismiss() won't dismiss this view self.closeDialog() - DispatchQueue.main.async { - let authenticationService = AuthenticationService() - if self.presenter.customers.count == 1 && authenticationService.authenticationType == .unset { - authenticationService.setAuthenticationType(.none) - - UIAlert("Secure data?", "Secure data with?", - UIAlertAction.ok { SceneDelegate.navigateToView(ProtectAppSettingsDialog()) }, - UIAlertAction.cancel(self.closeDialog)) - .show() - } + let authenticationService = AuthenticationService() + if self.presenter.customers.count == 1 && authenticationService.authenticationType == .unset { + authenticationService.setAuthenticationType(.none) + + UIAlert("Secure data?", "Secure data with?", + UIAlertAction.ok { SceneDelegate.navigateToView(ProtectAppSettingsDialog()) }, + UIAlertAction.cancel(self.closeDialog)) + .show() } } } @@ -121,7 +117,7 @@ struct AddAccountDialog: View { } private func closeDialog() { - self.presentation.wrappedValue.dismiss() + SceneDelegate.dismissCurrentView() } } diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/views/LoginDialog.swift b/ui/BankingiOSApp/BankingiOSApp/ui/views/LoginDialog.swift index 59c2d0e3..5aa55e6c 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/views/LoginDialog.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/views/LoginDialog.swift @@ -112,7 +112,7 @@ struct LoginDialog: View { } private func closeDialogAndDispatchLoginResult(_ authenticationSuccess: Bool) { - SceneDelegate.rootNavigationController?.popViewController(animated: false) + SceneDelegate.dismissCurrentView() self.loginResult(authenticationSuccess) }