Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] #32 - SignUpView alert 로직 변경 및 SignUpVC UI 구현 #33

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ public class CustomTextFieldView: UIView {
}
}

/// alert Label을 다른 CustomTextField에 보여주기 위한 delegate
weak var alertDelegate: CustomTextFieldView?

private var cancelBag = CancelBag()

// MARK: - UI Component
Expand Down Expand Up @@ -234,8 +237,18 @@ extension CustomTextFieldView {
return self
}

/// alertText를 다른 TextField에 보여주기 위한 delegate 설정
public func setAlertDelegate(_ textView: CustomTextFieldView) -> Self {
self.alertDelegate = textView
return self
}

/// 경고 문구 라벨의 text 설정
public func changeAlertLabelText(_ alertText: String) {
if let alertDelegate = alertDelegate {
alertDelegate.changeAlertLabelText(alertText)
return
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

새로운 방식으로 하니 더 깔끔해지네요!! 비대한 함수의 기능이 잘 분리된 것 같아요👍 👍 평소에 하듯이 alertDelegate를 Protocol로 구현해주면 확장성도 좋아질 것 같아요~

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

프로토콜로 바꿔서 반영했습니다! 감사합니다~~!!

self.alertlabel.text = alertText
self.alertlabel.isHidden = false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,6 @@ import Core
import DSKit

extension SignUpFormValidateResult {

var passwordAlertType: TextFieldAlertType {
switch self {
case .valid:
return .validInput(text: "")
case .invalid(let text):
if text == I18N.SignUp.invalidPasswordForm {
return .invalidInput(text: text)
}
return .validInput(text: "")
}
}

var passwordCheckAlertType: TextFieldAlertType {
switch self {
case .valid:
return .validInput(text: "")
case .invalid(let text):
if text == I18N.SignUp.passwordNotAccord {
return.invalidInput(text: text)
} else if text == I18N.SignUp.invalidPasswordForm {
return .invalidInput(text: text)
}
return .validInput(text: "")
}
}

func convertToTextFieldAlertType() -> TextFieldAlertType {
switch self {
case .valid(let text):
Expand Down Expand Up @@ -81,12 +54,13 @@ public class SignUpVC: UIViewController {
.setTextFieldType(.email)
.setAlertLabelEnabled(I18N.SignUp.invalidEmailForm)

private let passwordTextFieldView = CustomTextFieldView(type: .title)
private lazy var passwordTextFieldView = CustomTextFieldView(type: .title)
.setTitle(I18N.SignUp.password)
.setTextFieldType(.password)
.setPlaceholder(I18N.SignUp.passwordTextFieldPlaceholder)
.setAlertDelegate(passwordCheckTextFieldView)

private let passwordCheckTextFieldView = CustomTextFieldView(type: .plain)
private lazy var passwordCheckTextFieldView = CustomTextFieldView(type: .plain)
.setPlaceholder(I18N.SignUp.passwordCheckTextFieldPlaceholder)
.setTextFieldType(.password)
.setAlertLabelEnabled(I18N.SignUp.invalidPasswordForm)
Expand Down Expand Up @@ -138,17 +112,16 @@ extension SignUpVC {
.store(in: cancelBag)

output.passwordAlert
.sink { event in
print("event: \(event)")
} receiveValue: { [weak self] signUpFormValidateResult in
guard let self = self else { return }
let alertText = signUpFormValidateResult.convertToTextFieldAlertType().alertText
let needWarning = !alertText.isEmpty
self.passwordCheckTextFieldView.changeAlertLabelText(alertText)
self.passwordCheckTextFieldView.changeAlertLabelTextColor(toWarning: needWarning)
self.passwordTextFieldView.alertType = signUpFormValidateResult.passwordAlertType
self.passwordCheckTextFieldView.alertType = signUpFormValidateResult.passwordCheckAlertType
}.store(in: cancelBag)
.map { $0.convertToTextFieldAlertType() }
.assign(to: passwordTextFieldView.bindableInput(.alert),
on: passwordTextFieldView)
.store(in: cancelBag)

output.passwordAccordAlert
.map { $0.convertToTextFieldAlertType() }
.assign(to: passwordCheckTextFieldView.bindableInput(.alert),
on: passwordCheckTextFieldView)
.store(in: cancelBag)

output.isValidForm
.assign(to: \.isEnabled, on: registerButton)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class SignUpViewModel: ViewModelType {
var nicknameAlert = PassthroughSubject<SignUpFormValidateResult, Never>()
var emailAlert = PassthroughSubject<SignUpFormValidateResult, Never>()
var passwordAlert = PassthroughSubject<SignUpFormValidateResult, Never>()
var passwordAccordAlert = PassthroughSubject<SignUpFormValidateResult, Never>()
var isValidForm = PassthroughSubject<Bool, Never>()
}

Expand Down Expand Up @@ -98,14 +99,14 @@ extension SignUpViewModel {
useCase.isPasswordFormValid.combineLatest(useCase.isAccordPassword).sink { event in
print("SignUpViewModel - completion: \(event)")
} receiveValue: { (isFormValid, isAccordValid) in
if !isFormValid && !isAccordValid {
output.passwordAlert.send(.invalid(text: I18N.SignUp.invalidPasswordForm))
} else if !isFormValid && isAccordValid {
if !isFormValid {
output.passwordAlert.send(.invalid(text: I18N.SignUp.invalidPasswordForm))
} else if isFormValid && !isAccordValid {
output.passwordAlert.send(.invalid(text: (I18N.SignUp.passwordNotAccord)))
output.passwordAlert.send(.valid(text: ""))
output.passwordAccordAlert.send(.invalid(text: (I18N.SignUp.passwordNotAccord)))
} else {
output.passwordAlert.send(.valid(text: ""))
output.passwordAccordAlert.send(.valid(text: ""))
}
}.store(in: cancelBag)

Expand Down