fix register close
This commit is contained in:
parent
01756710a3
commit
53b90dc646
@ -124,7 +124,7 @@ struct LoginView: View {
|
||||
}
|
||||
.padding(.top, 10)
|
||||
.sheet(isPresented: $isShowingRegistration) {
|
||||
RegistrationView(viewModel: viewModel)
|
||||
RegistrationView(viewModel: viewModel, isPresented: $isShowingRegistration)
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
@ -9,6 +9,7 @@ import SwiftUI
|
||||
|
||||
struct RegistrationView: View {
|
||||
@ObservedObject var viewModel: LoginViewModel
|
||||
@Binding var isPresented: Bool
|
||||
@Environment(\.presentationMode) private var presentationMode
|
||||
|
||||
@State private var username: String = ""
|
||||
@ -40,19 +41,14 @@ struct RegistrationView: View {
|
||||
|
||||
var body: some View {
|
||||
NavigationView {
|
||||
|
||||
ScrollView {
|
||||
ZStack {
|
||||
ZStack(alignment: .top) {
|
||||
Color.clear
|
||||
.contentShape(Rectangle())
|
||||
.onTapGesture {
|
||||
hideKeyboard()
|
||||
}
|
||||
.onTapGesture { hideKeyboard() }
|
||||
|
||||
VStack(alignment: .leading, spacing: 16) {
|
||||
|
||||
Group {
|
||||
|
||||
HStack {
|
||||
TextField(NSLocalizedString("Логин", comment: "Логин"), text: $username)
|
||||
.autocapitalization(.none)
|
||||
@ -159,14 +155,15 @@ struct RegistrationView: View {
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
.navigationBarItems(trailing:
|
||||
Button(action: {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}) {
|
||||
}
|
||||
.navigationTitle(Text(NSLocalizedString("Регистрация", comment: "Регистрация")))
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .navigationBarTrailing) {
|
||||
Button(action: dismissSheet) {
|
||||
Text(NSLocalizedString("Закрыть", comment: "Закрыть"))
|
||||
}
|
||||
)
|
||||
.navigationTitle(Text(NSLocalizedString("Регистрация", comment: "Регистрация")))
|
||||
}
|
||||
}
|
||||
.alert(isPresented: $showError) {
|
||||
Alert(
|
||||
title: Text(NSLocalizedString("Ошибка регистрация", comment: "Ошибка")),
|
||||
@ -174,13 +171,6 @@ struct RegistrationView: View {
|
||||
dismissButton: .default(Text(NSLocalizedString("OK", comment: "")))
|
||||
)
|
||||
}
|
||||
}
|
||||
.onTapGesture {
|
||||
hideKeyboard()
|
||||
}
|
||||
}
|
||||
.onTapGesture {
|
||||
hideKeyboard()
|
||||
}
|
||||
}
|
||||
|
||||
@ -190,7 +180,7 @@ struct RegistrationView: View {
|
||||
viewModel.registerUser(username: username, password: password, invite: inviteCode.isEmpty ? nil : inviteCode) { success, message in
|
||||
isLoading = false
|
||||
if success {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
dismissSheet()
|
||||
} else {
|
||||
errorMessage = message ?? NSLocalizedString("Неизвестная ошибка.", comment: "")
|
||||
showError = true
|
||||
@ -198,6 +188,12 @@ struct RegistrationView: View {
|
||||
}
|
||||
}
|
||||
|
||||
private func dismissSheet() {
|
||||
hideKeyboard()
|
||||
isPresented = false
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}
|
||||
|
||||
private func hideKeyboard() {
|
||||
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
|
||||
}
|
||||
@ -208,6 +204,6 @@ struct RegistrationView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
let viewModel = LoginViewModel()
|
||||
viewModel.isLoading = false // чтобы убрать спиннер
|
||||
return RegistrationView(viewModel: viewModel)
|
||||
return RegistrationView(viewModel: viewModel, isPresented: .constant(true))
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user