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