Skip to content

Commit

Permalink
[Feat/#42] Onboarding - 버튼 활성화 관련 로직 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
kim-seonwoo committed Jan 10, 2024
1 parent 9892a9e commit e6472dd
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@
//
// Created by Seonwoo Kim on 1/3/24.
//
protocol HMHSelectButtonDelegate: AnyObject {
func updateAvailability(isEnabled: Bool)
}

import UIKit

import SnapKit
import Then

final class HMHSelectButton: UIButton {
weak var delegate: HMHSelectButtonDelegate?

@frozen
enum HMHSelectButtonType {
case solitary
Expand Down Expand Up @@ -105,14 +110,15 @@ final class HMHSelectButton: UIButton {
}

setChecked(true)
setAvailability()

case .multiple:
let selectedCount = (superview?.subviews.compactMap { ($0 as? HMHSelectButton)?.isChecked } ?? []).filter { $0 }.count

if selectedCount < 2 || isChecked {
setChecked(!isChecked)
setAvailability()
}

case .disabled:
return
}
Expand All @@ -121,4 +127,19 @@ final class HMHSelectButton: UIButton {
func setButtonText(buttonTitle: String) {
buttonContentLabel.text = buttonTitle
}

func setAvailability() {
if (superview?.subviews.compactMap { ($0 as? HMHSelectButton)?.isChecked } ?? []).filter { $0 }.count == 0 {
updateAvailability(status: false)
} else {
updateAvailability(status: true)
}

}

@objc
func updateAvailability(status: Bool) {
self.delegate?.updateAvailability(isEnabled: status)
print("tap")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ protocol NextViewPushDelegate: AnyObject {

class OnboardingBaseViewController: UIViewController {
weak var delegate: NextViewPushDelegate?

let mainTitleLabel = UILabel().then {
$0.textColor = .whiteText
$0.font = .iosTitle1Semibold22
Expand All @@ -32,13 +31,13 @@ class OnboardingBaseViewController: UIViewController {
var nextButtonText: String = StringLiteral.OnboardingButton.next
var mainTitleText: String = ""
var subTitleText: String = ""
let navigationBar = HMHNavigationBar(leftItem: .normal,
let navigationBar = HMHNavigationBar(leftItem: .normal,
isBackButton: true,
isTitleLabel: false,
isPointImage: false,
isBackGroundGray: false)
let progressBar = ProgressBarManager.shared.progressBarView
lazy var nextButton = OnboardingButton(buttonStatus: .enabled)
lazy var nextButton = OnboardingButton(buttonStatus: .disabled)
var step = 0

override func viewWillAppear(_ animated: Bool) {
Expand Down Expand Up @@ -102,6 +101,16 @@ class OnboardingBaseViewController: UIViewController {
func onTapButton() {
self.delegate?.didTapButton()
}

func updateNextButtonStatus(buttonStatus: Bool) {
if buttonStatus {
self.nextButton.backgroundColor = .bluePurpleButton
self.nextButton.isEnabled = true
} else {
self.nextButton.backgroundColor = .gray4
self.nextButton.isEnabled = false
}
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ final class ProblemSurveyViewController: OnboardingBaseViewController {
surveyView.secondButton.setButtonText(buttonTitle: StringLiteral.ProblemSurveySelect.secondSelect)
surveyView.thirdButton.setButtonText(buttonTitle: StringLiteral.ProblemSurveySelect.thirdSelect)
surveyView.fourthButton.setButtonText(buttonTitle: StringLiteral.ProblemSurveySelect.fourthSelect)

surveyView.firstButton.delegate = self
surveyView.secondButton.delegate = self
surveyView.thirdButton.delegate = self
surveyView.fourthButton.delegate = self
}
}

Expand All @@ -68,3 +73,9 @@ extension ProblemSurveyViewController: NextViewPushDelegate {
}
}

extension ProblemSurveyViewController: HMHSelectButtonDelegate {
func updateAvailability(isEnabled: Bool) {
print("taptap")
updateNextButtonStatus(buttonStatus: isEnabled)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ final class TimeSurveyViewController: OnboardingBaseViewController {
surveyView.secondButton.setButtonText(buttonTitle: StringLiteral.TimeSurveySelect.secondSelect)
surveyView.thirdButton.setButtonText(buttonTitle: StringLiteral.TimeSurveySelect.thirdSelect)
surveyView.fourthButton.setButtonText(buttonTitle: StringLiteral.TimeSurveySelect.fourthSelect)

surveyView.firstButton.delegate = self
surveyView.secondButton.delegate = self
surveyView.thirdButton.delegate = self
surveyView.fourthButton.delegate = self
}
}

Expand All @@ -67,3 +72,10 @@ extension TimeSurveyViewController: NextViewPushDelegate {
self.navigationController?.pushViewController(nextViewController, animated: false)
}
}

extension TimeSurveyViewController: HMHSelectButtonDelegate {
func updateAvailability(isEnabled: Bool) {
print("taptap")
updateNextButtonStatus(buttonStatus: isEnabled)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class OnboardingButton: UIButton {
case disabled
}

private var type: OnboardingButtonType = .disabled
var type: OnboardingButtonType = .disabled

private let buttonTitleLabel = UILabel().then {
$0.textColor = .whiteText
Expand Down

0 comments on commit e6472dd

Please sign in to comment.