Add username-suggestion (#690)

This commit is contained in:
Nathan Mattes 2022-12-28 14:58:57 +01:00
parent 98421802eb
commit 3e76f43637
2 changed files with 29 additions and 15 deletions

View File

@ -20,7 +20,7 @@ struct MastodonRegisterView: View {
var body: some View { var body: some View {
ScrollView(.vertical) { ScrollView(.vertical) {
let margin: CGFloat = 16 let margin: CGFloat = 16
VStack(alignment: .leading, spacing: 11) { VStack(alignment: .leading, spacing: 16) {
TextField(L10n.Scene.Register.Input.DisplayName.placeholder.localizedCapitalized, text: $viewModel.name) TextField(L10n.Scene.Register.Input.DisplayName.placeholder.localizedCapitalized, text: $viewModel.name)
.textContentType(.name) .textContentType(.name)
.disableAutocorrection(true) .disableAutocorrection(true)
@ -41,8 +41,23 @@ struct MastodonRegisterView: View {
.modifier(FormTextFieldModifier(validateState: viewModel.usernameValidateState)) .modifier(FormTextFieldModifier(validateState: viewModel.usernameValidateState))
.environment(\.layoutDirection, .leftToRight) // force LTR .environment(\.layoutDirection, .leftToRight) // force LTR
if let errorPrompt = viewModel.usernameErrorPrompt { if let errorPrompt = viewModel.usernameErrorPrompt {
Text(errorPrompt) VStack(alignment: .leading, spacing: 8) {
.modifier(FormFootnoteModifier()) Text(errorPrompt)
.font(Font(UIFontMetrics(forTextStyle: .caption1).scaledFont(for: .systemFont(ofSize: 13, weight: .regular))))
//FIXME: Better way than comparing strings
if errorPrompt == L10n.Scene.Register.Error.Reason.taken(L10n.Scene.Register.Error.Item.username) {
Button {
viewModel.usernameErrorPrompt = nil
viewModel.usernameValidateState = .empty
viewModel.username = "amazing_\(viewModel.username)"
} label: {
Text("amazing_\(viewModel.username)")
.foregroundColor(Asset.Colors.Brand.blurple.swiftUIColor)
.font(Font(UIFontMetrics(forTextStyle: .body).scaledFont(for: .systemFont(ofSize: 17, weight: .bold))))
}
}
}
} }
TextField(L10n.Scene.Register.Input.Email.placeholder.localizedCapitalized, text: $viewModel.email) TextField(L10n.Scene.Register.Input.Email.placeholder.localizedCapitalized, text: $viewModel.email)
.textContentType(.emailAddress) .textContentType(.emailAddress)
@ -109,23 +124,23 @@ struct MastodonRegisterView: View {
let borderColor: Color = { let borderColor: Color = {
switch validateState { switch validateState {
case .empty: return Color(Asset.Scene.Onboarding.textFieldBackground.color) case .empty: return Color(Asset.Scene.Onboarding.textFieldBackground.color)
case .invalid: return Color(Asset.Colors.TextField.invalid.color) case .invalid: return Color(Asset.Colors.TextField.invalid.color.withAlphaComponent(0.25))
case .valid: return Color(Asset.Scene.Onboarding.textFieldBackground.color) case .valid: return Color(Asset.Scene.Onboarding.textFieldBackground.color)
} }
}() }()
Color(Asset.Scene.Onboarding.textFieldBackground.color) borderColor
.cornerRadius(10) .cornerRadius(10)
content content
.padding() .padding()
.background(Color(Asset.Scene.Onboarding.textFieldBackground.color)) .background(borderColor)
.cornerRadius(10) .cornerRadius(10)
.overlay( // .overlay(
RoundedRectangle(cornerRadius: 10) // RoundedRectangle(cornerRadius: 10)
.stroke(borderColor, lineWidth: 1) // .stroke(borderColor, lineWidth: 1)
.animation(.easeInOut, value: validateState) // .animation(.easeInOut, value: validateState)
) // )
} }
} }
} }
@ -136,7 +151,6 @@ struct MastodonRegisterView: View {
content content
.font(.footnote) .font(.footnote)
.foregroundColor(foregroundColor) .foregroundColor(foregroundColor)
.padding(.horizontal)
} }
} }

View File

@ -5,9 +5,9 @@
"color-space" : "srgb", "color-space" : "srgb",
"components" : { "components" : {
"alpha" : "1.000", "alpha" : "1.000",
"blue" : "0.353", "blue" : "0x30",
"green" : "0.251", "green" : "0x3B",
"red" : "0.875" "red" : "0xFF"
} }
}, },
"idiom" : "universal" "idiom" : "universal"