From 3e61b8c21addb61ead3b8a7850422c0c8fa0c2cd Mon Sep 17 00:00:00 2001 From: IanRDavies Date: Thu, 24 Feb 2022 08:45:19 +0000 Subject: [PATCH] ios: display name validation (#364) * try to add warning text if display name has whitespace * simplify * layout/error icon Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> --- apps/ios/Shared/ContentView.swift | 34 +++++++++++++------------ apps/ios/Shared/Views/WelcomeView.swift | 31 ++++++++++++++++++---- 2 files changed, 44 insertions(+), 21 deletions(-) diff --git a/apps/ios/Shared/ContentView.swift b/apps/ios/Shared/ContentView.swift index 24cd35b187..36f233972c 100644 --- a/apps/ios/Shared/ContentView.swift +++ b/apps/ios/Shared/ContentView.swift @@ -13,24 +13,26 @@ struct ContentView: View { @State private var showNotificationAlert = false var body: some View { - if let user = chatModel.currentUser { - ChatListView(user: user) - .onAppear { - do { - try apiStartChat() - chatModel.chats = try apiGetChats() - } catch { - fatalError("Failed to start or load chats: \(error)") + ZStack { + if let user = chatModel.currentUser { + ChatListView(user: user) + .onAppear { + do { + try apiStartChat() + chatModel.chats = try apiGetChats() + } catch { + fatalError("Failed to start or load chats: \(error)") + } + ChatReceiver.shared.start() + NtfManager.shared.requestAuthorization(onDeny: { + alertManager.showAlert(notificationAlert()) + }) } - ChatReceiver.shared.start() - NtfManager.shared.requestAuthorization(onDeny: { - alertManager.showAlert(notificationAlert()) - }) - } - .alert(isPresented: $alertManager.presentAlert) { alertManager.alertView! } - } else { - WelcomeView() + } else { + WelcomeView() + } } + .alert(isPresented: $alertManager.presentAlert) { alertManager.alertView! } } func notificationAlert() -> Alert { diff --git a/apps/ios/Shared/Views/WelcomeView.swift b/apps/ios/Shared/Views/WelcomeView.swift index 02ab3d1653..65e356f31f 100644 --- a/apps/ios/Shared/Views/WelcomeView.swift +++ b/apps/ios/Shared/Views/WelcomeView.swift @@ -26,19 +26,35 @@ struct WelcomeView: View { Text("The messaging and application platform protecting your privacy and security.") .padding(.bottom, 8) Text("We don't store any of your contacts or messages (once delivered) on the servers.") - .padding(.bottom, 24) + .padding(.bottom, 32) Text("Create profile") .font(.largeTitle) .padding(.bottom) Text("Your profile is stored on your device and shared only with your contacts.") .padding(.bottom) - TextField("Display name", text: $displayName) - .textInputAutocapitalization(.never) - .disableAutocorrection(true) - .padding(.bottom) + ZStack(alignment: .topLeading) { + if !validDisplayName(displayName) { + Button { + AlertManager.shared.showAlertMsg( + title: "Display name", + message: "Display name can't contain spaces" + ) + } label: { + Image(systemName: "exclamationmark.circle") + .foregroundColor(.red) + .padding(.top, 4) + } + } + TextField("Display name", text: $displayName) + .textInputAutocapitalization(.never) + .disableAutocorrection(true) + .padding(.leading, 28) + } + .padding(.bottom) TextField("Full name (optional)", text: $fullName) .textInputAutocapitalization(.never) .disableAutocorrection(true) + .padding(.leading, 28) .padding(.bottom) Button("Create") { let profile = Profile( @@ -52,10 +68,15 @@ struct WelcomeView: View { fatalError("Failed to create user: \(error)") } } + .disabled(!validDisplayName(displayName)) } } .padding() } + + func validDisplayName(_ name: String) -> Bool { + name.firstIndex(of: " ") == nil + } } struct WelcomeView_Previews: PreviewProvider {