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 {
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,19 +41,23 @@ extension SceneDelegate {
return currentViewController
}
public static var currentNavigationItem: UINavigationItem? {
static var currentNavigationItem: UINavigationItem? {
currentViewController?.navigationItem
}
public static func navigateToView<Content: View>(_ view: Content) {
static func navigateToView<Content: View>(_ 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)
}
}

View File

@ -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)
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()
}
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()
}
}

View File

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