Skip to content

Commit

Permalink
[chore] #26 Move button state logic into SignUpFeature
Browse files Browse the repository at this point in the history
  • Loading branch information
mnbvcxzyj committed Jan 16, 2025
1 parent e30a830 commit a331be6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ class SignUpFeature: Feature {
struct State {
var progress: Double = 0.0
var isAgree: Bool = false
var buttonState: WithSuhyeonButtonState = .disabled
}

enum Intent {
case nextStep
case previousStep
case tapButton
case tapBackButton
}

enum SideEffect {
Expand All @@ -32,6 +33,7 @@ class SignUpFeature: Feature {
init() {
bindIntents()
updateProgress()
receiveState()
}

private func bindIntents() {
Expand All @@ -40,15 +42,29 @@ class SignUpFeature: Feature {
}.store(in: &cancellables)
}

private func receiveState() {
$state.sink { [weak self] _ in
DispatchQueue.main.async {
self?.updateButtonState()
}
}.store(in: &cancellables)

$currentContent.sink { [weak self] _ in
DispatchQueue.main.async {
self?.updateButtonState()
}
}.store(in: &cancellables)
}

func send(_ intent: Intent) {
intentSubject.send(intent)
}

func handleIntent(_ intent: Intent) {
switch intent {
case .nextStep:
case .tapButton:
moveToNextStep()
case .previousStep:
case .tapBackButton:
moveToPreviousStep()
}
}
Expand All @@ -75,6 +91,23 @@ class SignUpFeature: Feature {
}
}

private func updateButtonState() {
let newButtonState: WithSuhyeonButtonState

switch currentContent {
case .termsOfServiceView:
newButtonState = state.isAgree ? .enabled : .disabled
default:
newButtonState = .enabled
}

guard state.buttonState != newButtonState else {
return
}

state.buttonState = newButtonState
}

func changeSelectedContent(signUpContentCase: SignUpContentCase) {
currentContent = signUpContentCase
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,15 @@ struct SignUpView: View {

WithSuhyeonButton(
title: "다음",
buttonState: isNextStepEnabled() ? .enabled : .disabled,
clickable: isNextStepEnabled(),
buttonState: signUpFeature.state.buttonState,
clickable: signUpFeature.state.buttonState == .enabled,
onTapButton: {
signUpFeature.send(.nextStep)
signUpFeature.send(.tapButton)
}
)
.padding(.horizontal, 16)
}.environmentObject(signUpFeature)
}

private func isNextStepEnabled() -> Bool {
switch signUpFeature.currentContent {
case .termsOfServiceView:
return signUpFeature.state.isAgree
default:
return true
}
}
}

#Preview {
Expand Down

0 comments on commit a331be6

Please sign in to comment.