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>
This commit is contained in:
IanRDavies
2022-02-24 08:45:19 +00:00
committed by GitHub
parent 99bed645f3
commit 3e61b8c21a
2 changed files with 44 additions and 21 deletions
+18 -16
View File
@@ -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 {
+26 -5
View File
@@ -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 {