mv-experiment #1

Merged
fmodf merged 88 commits from mv-experiment into develop 2024-09-03 15:13:59 +00:00
2 changed files with 17 additions and 36 deletions
Showing only changes of commit b72ff93ebe - Show all commits

View file

@ -13,9 +13,6 @@ struct LoginScreen: View {
@FocusState private var focus: Field? @FocusState private var focus: Field?
@State private var isLoading = false
@State private var isError = false
#if DEBUG #if DEBUG
@State private var jidStr: String = "nartest1@conversations.im" @State private var jidStr: String = "nartest1@conversations.im"
@State private var pass: String = "nartest12345" @State private var pass: String = "nartest12345"
@ -98,16 +95,6 @@ struct LoginScreen: View {
} }
.padding(.horizontal, 32) .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 { private var loginInputValid: Bool {
@ -115,7 +102,9 @@ struct LoginScreen: View {
} }
private func tryLogin() async { private func tryLogin() async {
isLoading = true router.showModal {
LoadingScreen()
}
// login with fake timeout // login with fake timeout
async let sleep: Void? = try? await Task.sleep(nanoseconds: 1 * NSEC_PER_SEC) async let sleep: Void? = try? await Task.sleep(nanoseconds: 1 * NSEC_PER_SEC)
@ -125,12 +114,17 @@ struct LoginScreen: View {
switch result { switch result {
case .success(let client): case .success(let client):
clientsStore.addNewClient(client) clientsStore.addNewClient(client)
isLoading = false router.dismissModal()
isError = false
case .failure: case .failure:
isLoading = false router.dismissModal()
isError = true router.showAlert(
.alert,
title: L10n.Global.Error.title,
subtitle: L10n.Login.error
) {
Button(L10n.Global.ok, role: .cancel) {}
}
} }
} }
} }

View file

@ -1,23 +1,10 @@
import Foundation
import SwiftUI import SwiftUI
public extension View { struct LoadingScreen: View {
func loadingOverlay() -> some View { var body: some View {
modifier(LoadingOverlay()) GeometryReader { geo in
}
}
struct LoadingOverlay: ViewModifier {
func body(content: Content) -> some View {
ZStack {
content
loadingView
}
}
private var loadingView: some View {
GeometryReader { proxyReader in
ZStack { ZStack {
// background with opacity
Color.Material.Elements.active.opacity(0.3) Color.Material.Elements.active.opacity(0.3)
.frame(maxWidth: .infinity, maxHeight: .infinity) .frame(maxWidth: .infinity, maxHeight: .infinity)
@ -26,7 +13,7 @@ struct LoadingOverlay: ViewModifier {
.progressViewStyle( .progressViewStyle(
CircularProgressViewStyle(tint: .Material.Elements.active) 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) .controlSize(.large)
} }
} }