2
2
mirror of https://github.com/mastodon/mastodon-ios synced 2025-04-11 22:58:02 +02:00

fix: update return key type for form text fields. Fix username check result not update UI issue

This commit is contained in:
CMK 2021-06-16 15:56:18 +08:00
parent 1c1189df7d
commit 7c895bdfe9
2 changed files with 28 additions and 5 deletions

View File

@ -109,7 +109,7 @@ final class MastodonRegisterViewController: UIViewController, NeedsDependency, O
let usernameTextField: UITextField = { let usernameTextField: UITextField = {
let textField = UITextField() let textField = UITextField()
textField.returnKeyType = .next
textField.autocapitalizationType = .none textField.autocapitalizationType = .none
textField.autocorrectionType = .no textField.autocorrectionType = .no
textField.backgroundColor = Asset.Colors.Background.secondaryGroupedSystemBackground.color textField.backgroundColor = Asset.Colors.Background.secondaryGroupedSystemBackground.color
@ -160,6 +160,7 @@ final class MastodonRegisterViewController: UIViewController, NeedsDependency, O
let displayNameTextField: UITextField = { let displayNameTextField: UITextField = {
let textField = UITextField() let textField = UITextField()
textField.returnKeyType = .next
textField.autocapitalizationType = .none textField.autocapitalizationType = .none
textField.autocorrectionType = .no textField.autocorrectionType = .no
textField.backgroundColor = Asset.Colors.Background.secondaryGroupedSystemBackground.color textField.backgroundColor = Asset.Colors.Background.secondaryGroupedSystemBackground.color
@ -177,6 +178,7 @@ final class MastodonRegisterViewController: UIViewController, NeedsDependency, O
let emailTextField: UITextField = { let emailTextField: UITextField = {
let textField = UITextField() let textField = UITextField()
textField.returnKeyType = .next
textField.autocapitalizationType = .none textField.autocapitalizationType = .none
textField.autocorrectionType = .no textField.autocorrectionType = .no
textField.keyboardType = .emailAddress textField.keyboardType = .emailAddress
@ -202,6 +204,7 @@ final class MastodonRegisterViewController: UIViewController, NeedsDependency, O
let passwordTextField: UITextField = { let passwordTextField: UITextField = {
let textField = UITextField() let textField = UITextField()
textField.returnKeyType = .next // set to "Return" depends on if the last input field or not
textField.autocapitalizationType = .none textField.autocapitalizationType = .none
textField.autocorrectionType = .no textField.autocorrectionType = .no
textField.keyboardType = .asciiCapable textField.keyboardType = .asciiCapable
@ -235,6 +238,7 @@ final class MastodonRegisterViewController: UIViewController, NeedsDependency, O
lazy var reasonTextField: UITextField = { lazy var reasonTextField: UITextField = {
let textField = UITextField() let textField = UITextField()
textField.returnKeyType = .next // set to "Return" depends on if the last input field or not
textField.autocapitalizationType = .none textField.autocapitalizationType = .none
textField.autocorrectionType = .no textField.autocorrectionType = .no
textField.backgroundColor = Asset.Colors.Background.secondaryGroupedSystemBackground.color textField.backgroundColor = Asset.Colors.Background.secondaryGroupedSystemBackground.color
@ -393,11 +397,10 @@ extension MastodonRegisterViewController {
// return // return
if viewModel.approvalRequired { if viewModel.approvalRequired {
passwordTextField.returnKeyType = .continue reasonTextField.returnKeyType = .done
} else { } else {
passwordTextField.returnKeyType = .done passwordTextField.returnKeyType = .done
} }
reasonTextField.returnKeyType = .done
// button // button
stackView.addArrangedSubview(buttonContainer) stackView.addArrangedSubview(buttonContainer)
@ -657,6 +660,25 @@ extension MastodonRegisterViewController: UITextFieldDelegate {
} }
} }
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 { func textFieldShouldReturn(_ textField: UITextField) -> Bool {
switch textField { switch textField {
case usernameTextField: case usernameTextField:

View File

@ -106,6 +106,7 @@ final class MastodonRegisterViewModel {
case .success: case .success:
let text = L10n.Scene.Register.Error.Reason.taken(L10n.Scene.Register.Error.Item.username) let text = L10n.Scene.Register.Error.Reason.taken(L10n.Scene.Register.Error.Item.username)
self.usernameErrorPrompt.value = MastodonRegisterViewModel.errorPromptAttributedString(for: text) self.usernameErrorPrompt.value = MastodonRegisterViewModel.errorPromptAttributedString(for: text)
self.usernameValidateState.value = .invalid
case .failure: case .failure:
break break
} }