chore: make code clear
This commit is contained in:
parent
522702386c
commit
68d5365295
|
@ -97,7 +97,7 @@ final class MastodonRegisterViewController: UIViewController, NeedsDependency, O
|
||||||
textField.autocapitalizationType = .none
|
textField.autocapitalizationType = .none
|
||||||
textField.autocorrectionType = .no
|
textField.autocorrectionType = .no
|
||||||
textField.backgroundColor = .white
|
textField.backgroundColor = .white
|
||||||
textField.textColor = .black
|
textField.textColor = Asset.Colors.Label.secondary.color
|
||||||
textField.attributedPlaceholder = NSAttributedString(string: L10n.Scene.Register.Input.Username.placeholder,
|
textField.attributedPlaceholder = NSAttributedString(string: L10n.Scene.Register.Input.Username.placeholder,
|
||||||
attributes: [NSAttributedString.Key.foregroundColor: Asset.Colors.lightSecondaryText.color,
|
attributes: [NSAttributedString.Key.foregroundColor: Asset.Colors.lightSecondaryText.color,
|
||||||
NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: .headline)])
|
NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: .headline)])
|
||||||
|
@ -118,7 +118,7 @@ final class MastodonRegisterViewController: UIViewController, NeedsDependency, O
|
||||||
textField.autocapitalizationType = .none
|
textField.autocapitalizationType = .none
|
||||||
textField.autocorrectionType = .no
|
textField.autocorrectionType = .no
|
||||||
textField.backgroundColor = .white
|
textField.backgroundColor = .white
|
||||||
textField.textColor = .black
|
textField.textColor = Asset.Colors.Label.secondary.color
|
||||||
textField.attributedPlaceholder = NSAttributedString(string: L10n.Scene.Register.Input.DisplayName.placeholder,
|
textField.attributedPlaceholder = NSAttributedString(string: L10n.Scene.Register.Input.DisplayName.placeholder,
|
||||||
attributes: [NSAttributedString.Key.foregroundColor: Asset.Colors.lightSecondaryText.color,
|
attributes: [NSAttributedString.Key.foregroundColor: Asset.Colors.lightSecondaryText.color,
|
||||||
NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: .headline)])
|
NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: .headline)])
|
||||||
|
@ -135,7 +135,7 @@ final class MastodonRegisterViewController: UIViewController, NeedsDependency, O
|
||||||
textField.autocorrectionType = .no
|
textField.autocorrectionType = .no
|
||||||
textField.keyboardType = .emailAddress
|
textField.keyboardType = .emailAddress
|
||||||
textField.backgroundColor = .white
|
textField.backgroundColor = .white
|
||||||
textField.textColor = .black
|
textField.textColor = Asset.Colors.Label.secondary.color
|
||||||
textField.attributedPlaceholder = NSAttributedString(string: L10n.Scene.Register.Input.Email.placeholder,
|
textField.attributedPlaceholder = NSAttributedString(string: L10n.Scene.Register.Input.Email.placeholder,
|
||||||
attributes: [NSAttributedString.Key.foregroundColor: Asset.Colors.lightSecondaryText.color,
|
attributes: [NSAttributedString.Key.foregroundColor: Asset.Colors.lightSecondaryText.color,
|
||||||
NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: .headline)])
|
NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: .headline)])
|
||||||
|
@ -159,7 +159,7 @@ final class MastodonRegisterViewController: UIViewController, NeedsDependency, O
|
||||||
textField.keyboardType = .asciiCapable
|
textField.keyboardType = .asciiCapable
|
||||||
textField.isSecureTextEntry = true
|
textField.isSecureTextEntry = true
|
||||||
textField.backgroundColor = .white
|
textField.backgroundColor = .white
|
||||||
textField.textColor = .black
|
textField.textColor = Asset.Colors.Label.secondary.color
|
||||||
textField.attributedPlaceholder = NSAttributedString(string: L10n.Scene.Register.Input.Password.placeholder,
|
textField.attributedPlaceholder = NSAttributedString(string: L10n.Scene.Register.Input.Password.placeholder,
|
||||||
attributes: [NSAttributedString.Key.foregroundColor: Asset.Colors.lightSecondaryText.color,
|
attributes: [NSAttributedString.Key.foregroundColor: Asset.Colors.lightSecondaryText.color,
|
||||||
NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: .headline)])
|
NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: .headline)])
|
||||||
|
@ -175,7 +175,7 @@ final class MastodonRegisterViewController: UIViewController, NeedsDependency, O
|
||||||
textField.autocapitalizationType = .none
|
textField.autocapitalizationType = .none
|
||||||
textField.autocorrectionType = .no
|
textField.autocorrectionType = .no
|
||||||
textField.backgroundColor = .white
|
textField.backgroundColor = .white
|
||||||
textField.textColor = .black
|
textField.textColor = Asset.Colors.Label.secondary.color
|
||||||
textField.attributedPlaceholder = NSAttributedString(string: L10n.Scene.Register.Input.Invite.registrationUserInviteRequest,
|
textField.attributedPlaceholder = NSAttributedString(string: L10n.Scene.Register.Input.Invite.registrationUserInviteRequest,
|
||||||
attributes: [NSAttributedString.Key.foregroundColor: Asset.Colors.lightSecondaryText.color,
|
attributes: [NSAttributedString.Key.foregroundColor: Asset.Colors.lightSecondaryText.color,
|
||||||
NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: .headline)])
|
NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: .headline)])
|
||||||
|
@ -242,7 +242,7 @@ extension MastodonRegisterViewController {
|
||||||
stackView.addArrangedSubview(emailTextField)
|
stackView.addArrangedSubview(emailTextField)
|
||||||
stackView.addArrangedSubview(passwordTextField)
|
stackView.addArrangedSubview(passwordTextField)
|
||||||
stackView.addArrangedSubview(passwordCheckLabel)
|
stackView.addArrangedSubview(passwordCheckLabel)
|
||||||
if self.viewModel.inviteEnabled {
|
if self.viewModel.approvalRequired {
|
||||||
stackView.addArrangedSubview(inviteTextField)
|
stackView.addArrangedSubview(inviteTextField)
|
||||||
}
|
}
|
||||||
// scrollView
|
// scrollView
|
||||||
|
@ -463,7 +463,7 @@ extension MastodonRegisterViewController {
|
||||||
}
|
}
|
||||||
.store(in: &disposeBag)
|
.store(in: &disposeBag)
|
||||||
|
|
||||||
if self.viewModel.inviteEnabled {
|
if self.viewModel.approvalRequired {
|
||||||
|
|
||||||
inviteTextField.delegate = self
|
inviteTextField.delegate = self
|
||||||
NSLayoutConstraint.activate([
|
NSLayoutConstraint.activate([
|
||||||
|
|
|
@ -33,9 +33,9 @@ final class MastodonRegisterViewModel {
|
||||||
let isRegistering = CurrentValueSubject<Bool, Never>(false)
|
let isRegistering = CurrentValueSubject<Bool, Never>(false)
|
||||||
|
|
||||||
// output
|
// output
|
||||||
lazy var inviteEnabled: Bool = {
|
lazy var approvalRequired: Bool = {
|
||||||
if let inviteEnabled = instance.invitesEnabled {
|
if let approvalRequired = instance.approvalRequired {
|
||||||
return inviteEnabled
|
return approvalRequired
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}()
|
}()
|
||||||
|
@ -106,7 +106,7 @@ final class MastodonRegisterViewModel {
|
||||||
}
|
}
|
||||||
.assign(to: \.value, on: passwordValidateState)
|
.assign(to: \.value, on: passwordValidateState)
|
||||||
.store(in: &disposeBag)
|
.store(in: &disposeBag)
|
||||||
if inviteEnabled {
|
if approvalRequired {
|
||||||
invite
|
invite
|
||||||
.map { invite in
|
.map { invite in
|
||||||
guard !invite.isEmpty else { return .empty }
|
guard !invite.isEmpty else { return .empty }
|
||||||
|
@ -115,26 +115,21 @@ final class MastodonRegisterViewModel {
|
||||||
.assign(to: \.value, on: inviteValidateState)
|
.assign(to: \.value, on: inviteValidateState)
|
||||||
.store(in: &disposeBag)
|
.store(in: &disposeBag)
|
||||||
}
|
}
|
||||||
let publisherOne = Publishers.CombineLatest(
|
let publisherOne = Publishers.CombineLatest4(
|
||||||
usernameValidateState.eraseToAnyPublisher(),
|
usernameValidateState.eraseToAnyPublisher(),
|
||||||
displayNameValidateState.eraseToAnyPublisher()
|
displayNameValidateState.eraseToAnyPublisher(),
|
||||||
)
|
|
||||||
let publisherTwo = Publishers.CombineLatest3(
|
|
||||||
emailValidateState.eraseToAnyPublisher(),
|
emailValidateState.eraseToAnyPublisher(),
|
||||||
passwordValidateState.eraseToAnyPublisher(),
|
passwordValidateState.eraseToAnyPublisher()
|
||||||
inviteValidateState.eraseToAnyPublisher()
|
).map {
|
||||||
)
|
$0.0 == .valid && $0.1 == .valid && $0.2 == .valid && $0.3 == .valid
|
||||||
|
}
|
||||||
|
|
||||||
Publishers.CombineLatest(
|
Publishers.CombineLatest(
|
||||||
publisherOne,
|
publisherOne,
|
||||||
publisherTwo
|
approvalRequired ? inviteValidateState.map {$0 == .valid}.eraseToAnyPublisher() : Just(true).eraseToAnyPublisher()
|
||||||
)
|
)
|
||||||
.map { [weak self] in
|
.map {
|
||||||
guard let self = self else { return false }
|
return $0 && $1
|
||||||
if self.inviteEnabled {
|
|
||||||
return $0.0.0 == .valid && $0.0.1 == .valid && $0.1.0 == .valid && $0.1.1 == .valid && $0.1.2 == .valid
|
|
||||||
} else {
|
|
||||||
return $0.0.0 == .valid && $0.0.1 == .valid && $0.1.0 == .valid && $0.1.1 == .valid
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.assign(to: \.value, on: isAllValid)
|
.assign(to: \.value, on: isAllValid)
|
||||||
.store(in: &disposeBag)
|
.store(in: &disposeBag)
|
||||||
|
|
Loading…
Reference in New Issue