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 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 {

View File

@ -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
}