Dismissing now AddAccountDialog manually so that we can show 'Secure data?' alert synchronously

This commit is contained in:
dankito 2020-09-07 15:03:22 +02:00
parent 3d11614921
commit 6201f277cc
3 changed files with 24 additions and 24 deletions

View File

@ -11,27 +11,27 @@ extension AppDelegate {
extension SceneDelegate { extension SceneDelegate {
public static var currentWindow: UIWindow { static var currentWindow: UIWindow {
UIApplication.shared.windows.first(where: { (window) -> Bool in window.isKeyWindow})! 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 currentWindow.rootViewController
} }
public static var rootNavigationController: UINavigationController? { static var rootNavigationController: UINavigationController? {
rootViewController as? UINavigationController rootViewController as? UINavigationController
} }
public static var rootTabBarController: UITabBarController? { static var rootTabBarController: UITabBarController? {
rootNavigationController?.viewControllers.first as? UITabBarController rootNavigationController?.viewControllers.first as? UITabBarController
} }
public static var currentViewController: UIViewController? { static var currentViewController: UIViewController? {
var currentViewController = rootTabBarController?.selectedViewController ?? rootTabBarController var currentViewController = rootTabBarController?.selectedViewController ?? rootTabBarController
while currentViewController?.presentedViewController != nil { while currentViewController?.presentedViewController != nil {
@ -41,19 +41,23 @@ extension SceneDelegate {
return currentViewController return currentViewController
} }
public static var currentNavigationItem: UINavigationItem? { static var currentNavigationItem: UINavigationItem? {
currentViewController?.navigationItem currentViewController?.navigationItem
} }
public static func navigateToView<Content: View>(_ view: Content) { static func navigateToView<Content: View>(_ view: Content) {
navigateToViewController(UIHostingController(rootView: view)) navigateToViewController(UIHostingController(rootView: view))
} }
public static func navigateToViewController(_ viewController: UIViewController) { static func navigateToViewController(_ viewController: UIViewController) {
rootNavigationController?.pushViewController(viewController, animated: true) rootNavigationController?.pushViewController(viewController, animated: true)
} }
static func dismissCurrentView() {
rootNavigationController?.popViewController(animated: false)
}
} }

View File

@ -5,8 +5,6 @@ import Combine
struct AddAccountDialog: View { struct AddAccountDialog: View {
@Environment(\.presentationMode) var presentation
@State private var bank: BankInfo? = nil @State private var bank: BankInfo? = nil
@State private var customerId = "" @State private var customerId = ""
@ -102,7 +100,6 @@ struct AddAccountDialog: View {
DispatchQueue.main.async { // dispatch async as may EnterTanDialog is still displayed so dismiss() won't dismiss this view DispatchQueue.main.async { // dispatch async as may EnterTanDialog is still displayed so dismiss() won't dismiss this view
self.closeDialog() self.closeDialog()
DispatchQueue.main.async {
let authenticationService = AuthenticationService() let authenticationService = AuthenticationService()
if self.presenter.customers.count == 1 && authenticationService.authenticationType == .unset { if self.presenter.customers.count == 1 && authenticationService.authenticationType == .unset {
authenticationService.setAuthenticationType(.none) authenticationService.setAuthenticationType(.none)
@ -114,14 +111,13 @@ struct AddAccountDialog: View {
} }
} }
} }
}
else { else {
self.errorMessage = Message(title: Text("Could not add account"), message: Text("Error message from your bank \(response.errorToShowToUser ?? "")")) self.errorMessage = Message(title: Text("Could not add account"), message: Text("Error message from your bank \(response.errorToShowToUser ?? "")"))
} }
} }
private func closeDialog() { private func closeDialog() {
self.presentation.wrappedValue.dismiss() SceneDelegate.dismissCurrentView()
} }
} }

View File

@ -112,7 +112,7 @@ struct LoginDialog: View {
} }
private func closeDialogAndDispatchLoginResult(_ authenticationSuccess: Bool) { private func closeDialogAndDispatchLoginResult(_ authenticationSuccess: Bool) {
SceneDelegate.rootNavigationController?.popViewController(animated: false) SceneDelegate.dismissCurrentView()
self.loginResult(authenticationSuccess) self.loginResult(authenticationSuccess)
} }