From b72ff93ebe290c6edfd9ac7109788f1f584a537f Mon Sep 17 00:00:00 2001 From: fmodf Date: Sun, 11 Aug 2024 17:47:54 +0200 Subject: [PATCH] wip --- .../View/Entering/LoginScreen.swift | 30 ++++++++----------- .../SharedComponents/LoadingScreen.swift} | 23 ++++---------- 2 files changed, 17 insertions(+), 36 deletions(-) rename ConversationsClassic/{UIToolkit/View+Loader.swift => View/SharedComponents/LoadingScreen.swift} (54%) diff --git a/ConversationsClassic/View/Entering/LoginScreen.swift b/ConversationsClassic/View/Entering/LoginScreen.swift index 62e0cfe..288705e 100644 --- a/ConversationsClassic/View/Entering/LoginScreen.swift +++ b/ConversationsClassic/View/Entering/LoginScreen.swift @@ -13,9 +13,6 @@ struct LoginScreen: View { @FocusState private var focus: Field? - @State private var isLoading = false - @State private var isError = false - #if DEBUG @State private var jidStr: String = "nartest1@conversations.im" @State private var pass: String = "nartest12345" @@ -98,16 +95,6 @@ struct LoginScreen: View { } .padding(.horizontal, 32) } - .if(isLoading) { - $0.loadingOverlay() - } - .alert(isPresented: $isError) { - Alert( - title: Text(L10n.Global.Error.title), - message: Text(L10n.Login.error), - dismissButton: .default(Text(L10n.Global.ok)) - ) - } } private var loginInputValid: Bool { @@ -115,7 +102,9 @@ struct LoginScreen: View { } private func tryLogin() async { - isLoading = true + router.showModal { + LoadingScreen() + } // login with fake timeout async let sleep: Void? = try? await Task.sleep(nanoseconds: 1 * NSEC_PER_SEC) @@ -125,12 +114,17 @@ struct LoginScreen: View { switch result { case .success(let client): clientsStore.addNewClient(client) - isLoading = false - isError = false + router.dismissModal() case .failure: - isLoading = false - isError = true + router.dismissModal() + router.showAlert( + .alert, + title: L10n.Global.Error.title, + subtitle: L10n.Login.error + ) { + Button(L10n.Global.ok, role: .cancel) {} + } } } } diff --git a/ConversationsClassic/UIToolkit/View+Loader.swift b/ConversationsClassic/View/SharedComponents/LoadingScreen.swift similarity index 54% rename from ConversationsClassic/UIToolkit/View+Loader.swift rename to ConversationsClassic/View/SharedComponents/LoadingScreen.swift index 37f910c..154987a 100644 --- a/ConversationsClassic/UIToolkit/View+Loader.swift +++ b/ConversationsClassic/View/SharedComponents/LoadingScreen.swift @@ -1,23 +1,10 @@ -import Foundation import SwiftUI -public extension View { - func loadingOverlay() -> some View { - modifier(LoadingOverlay()) - } -} - -struct LoadingOverlay: ViewModifier { - func body(content: Content) -> some View { - ZStack { - content - loadingView - } - } - - private var loadingView: some View { - GeometryReader { proxyReader in +struct LoadingScreen: View { + var body: some View { + GeometryReader { geo in ZStack { + // background with opacity Color.Material.Elements.active.opacity(0.3) .frame(maxWidth: .infinity, maxHeight: .infinity) @@ -26,7 +13,7 @@ struct LoadingOverlay: ViewModifier { .progressViewStyle( CircularProgressViewStyle(tint: .Material.Elements.active) ) - .position(x: proxyReader.size.width / 2, y: proxyReader.size.height / 2) + .position(x: geo.size.width / 2, y: geo.size.height / 2) .controlSize(.large) } }