diff --git a/Mastodon/Scene/Onboarding/Register/MastodonRegisterViewController.swift b/Mastodon/Scene/Onboarding/Register/MastodonRegisterViewController.swift index c2342f3a..ebd9b6ea 100644 --- a/Mastodon/Scene/Onboarding/Register/MastodonRegisterViewController.swift +++ b/Mastodon/Scene/Onboarding/Register/MastodonRegisterViewController.swift @@ -109,7 +109,7 @@ final class MastodonRegisterViewController: UIViewController, NeedsDependency, O let usernameTextField: UITextField = { let textField = UITextField() - + textField.returnKeyType = .next textField.autocapitalizationType = .none textField.autocorrectionType = .no textField.backgroundColor = Asset.Colors.Background.secondaryGroupedSystemBackground.color @@ -160,6 +160,7 @@ final class MastodonRegisterViewController: UIViewController, NeedsDependency, O let displayNameTextField: UITextField = { let textField = UITextField() + textField.returnKeyType = .next textField.autocapitalizationType = .none textField.autocorrectionType = .no textField.backgroundColor = Asset.Colors.Background.secondaryGroupedSystemBackground.color @@ -177,6 +178,7 @@ final class MastodonRegisterViewController: UIViewController, NeedsDependency, O let emailTextField: UITextField = { let textField = UITextField() + textField.returnKeyType = .next textField.autocapitalizationType = .none textField.autocorrectionType = .no textField.keyboardType = .emailAddress @@ -202,6 +204,7 @@ final class MastodonRegisterViewController: UIViewController, NeedsDependency, O let passwordTextField: UITextField = { let textField = UITextField() + textField.returnKeyType = .next // set to "Return" depends on if the last input field or not textField.autocapitalizationType = .none textField.autocorrectionType = .no textField.keyboardType = .asciiCapable @@ -235,6 +238,7 @@ final class MastodonRegisterViewController: UIViewController, NeedsDependency, O lazy var reasonTextField: UITextField = { let textField = UITextField() + textField.returnKeyType = .next // set to "Return" depends on if the last input field or not textField.autocapitalizationType = .none textField.autocorrectionType = .no textField.backgroundColor = Asset.Colors.Background.secondaryGroupedSystemBackground.color @@ -391,14 +395,13 @@ extension MastodonRegisterViewController { stackView.setCustomSpacing(6, after: passwordTextField) stackView.setCustomSpacing(32, after: passwordCheckLabel) - //return + // return if viewModel.approvalRequired { - passwordTextField.returnKeyType = .continue + reasonTextField.returnKeyType = .done } else { passwordTextField.returnKeyType = .done } - reasonTextField.returnKeyType = .done - + // button stackView.addArrangedSubview(buttonContainer) signUpButton.translatesAutoresizingMaskIntoConstraints = false @@ -656,6 +659,25 @@ extension MastodonRegisterViewController: UITextFieldDelegate { break } } + + func textFieldDidEndEditing(_ textField: UITextField) { + let text = textField.text?.trimmingCharacters(in: .whitespacesAndNewlines) ?? "" + + switch textField { + case usernameTextField: + viewModel.username.value = text + case displayNameTextField: + viewModel.displayName.value = text + case emailTextField: + viewModel.email.value = text + case passwordTextField: + viewModel.password.value = text + case reasonTextField: + viewModel.reason.value = text + default: + break + } + } func textFieldShouldReturn(_ textField: UITextField) -> Bool { switch textField { diff --git a/Mastodon/Scene/Onboarding/Register/MastodonRegisterViewModel.swift b/Mastodon/Scene/Onboarding/Register/MastodonRegisterViewModel.swift index 85b934a2..6c9e0754 100644 --- a/Mastodon/Scene/Onboarding/Register/MastodonRegisterViewModel.swift +++ b/Mastodon/Scene/Onboarding/Register/MastodonRegisterViewModel.swift @@ -106,6 +106,7 @@ final class MastodonRegisterViewModel { case .success: let text = L10n.Scene.Register.Error.Reason.taken(L10n.Scene.Register.Error.Item.username) self.usernameErrorPrompt.value = MastodonRegisterViewModel.errorPromptAttributedString(for: text) + self.usernameValidateState.value = .invalid case .failure: break }