Skip to content

Commit

Permalink
refactor/#277 변수 속성 맞게 재정렬, viewController에서 rootView와 viewModel의 네이밍…
Browse files Browse the repository at this point in the history
… 통일, extension 함수 분리
  • Loading branch information
youz2me committed Aug 8, 2024
1 parent eeed63d commit b5219d6
Show file tree
Hide file tree
Showing 19 changed files with 202 additions and 183 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ class CheckInviteCodeViewController: BaseViewController {

// MARK: Property

private let checkInviteCodeView: CheckInviteCodeView = CheckInviteCodeView()
private let rootView: CheckInviteCodeView = CheckInviteCodeView()


// MARK: LifeCycle

override func loadView() {
view = checkInviteCodeView
view = rootView
}

override func viewWillAppear(_ animated: Bool) {
Expand All @@ -44,11 +44,11 @@ class CheckInviteCodeViewController: BaseViewController {
}

override func setupAction() {
checkInviteCodeView.enterInviteCodeView.addGestureRecognizer(UITapGestureRecognizer(
rootView.enterInviteCodeView.addGestureRecognizer(UITapGestureRecognizer(
target: self,
action: #selector(inviteCodeViewDidTap)
))
checkInviteCodeView.createMeetingView.addGestureRecognizer(UITapGestureRecognizer(
rootView.createMeetingView.addGestureRecognizer(UITapGestureRecognizer(
target: self,
action: #selector(createMeetingViewDidTap)
))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ class CreateMeetingView: BaseView {


// MARK: Property

private let mainTitleLabel: UILabel = UILabel().then {
$0.setText("모임 이름을\n입력해 주세요", style: .head01)
}

let nameTextField: CustomTextField = CustomTextField(
placeHolder: "모임 이름을 입력해 주세요"
Expand All @@ -29,6 +25,10 @@ class CreateMeetingView: BaseView {
isEnabled: false
)

private let mainTitleLabel: UILabel = UILabel().then {
$0.setText("모임 이름을\n입력해 주세요", style: .head01)
}


// MARK: - Setup

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ class CreateMeetingViewController: BaseViewController {

// MARK: Property

private let createMeetingViewModel: CreateMeetingViewModel
private let createMeetingView: CreateMeetingView = CreateMeetingView()
private let viewModel: CreateMeetingViewModel
private let rootView: CreateMeetingView = CreateMeetingView()


// MARK: - LifeCycle

init(viewModel: CreateMeetingViewModel) {
self.createMeetingViewModel = viewModel
self.viewModel = viewModel

super.init(nibName: nil, bundle: nil)
}
Expand All @@ -29,7 +29,7 @@ class CreateMeetingViewController: BaseViewController {
}

override func loadView() {
view = createMeetingView
view = rootView
}

override func viewDidLoad() {
Expand Down Expand Up @@ -60,12 +60,12 @@ class CreateMeetingViewController: BaseViewController {
}

override func setupAction() {
createMeetingView.nameTextField.addTarget(
rootView.nameTextField.addTarget(
self,
action: #selector(textFieldDidChange(_:)),
for: .editingChanged
)
createMeetingView.presentButton.addTarget(
rootView.presentButton.addTarget(
self,
action: #selector(presentButtonDidTap),
for: .touchUpInside
Expand All @@ -84,45 +84,45 @@ class CreateMeetingViewController: BaseViewController {

private extension CreateMeetingViewController {
func setupBinding() {
createMeetingViewModel.inviteCodeState.bind(with: self) { owner, state in
viewModel.inviteCodeState.bind(with: self) { owner, state in
switch state {
case .empty, .invalid:
owner.createMeetingView.presentButton.isEnabled = false
owner.rootView.presentButton.isEnabled = false
case .valid:
owner.createMeetingView.presentButton.isEnabled = true
owner.rootView.presentButton.isEnabled = true
}

owner.createMeetingViewModel.characterCount.bind(with: self) { owner, count in
owner.createMeetingView.characterLabel.text = count
owner.viewModel.characterCount.bind(with: self) { owner, count in
owner.rootView.characterLabel.text = count
}
}
}

@objc
func textFieldDidChange(_ textField: UITextField) {
createMeetingViewModel.validateName(textField.text ?? "")
viewModel.validateName(textField.text ?? "")
}

@objc
func dismissKeyboard() {
view.endEditing(true)
createMeetingView.nameTextField.layer.borderColor = UIColor.gray3.cgColor
rootView.nameTextField.layer.borderColor = UIColor.gray3.cgColor
}

@objc
func presentButtonDidTap() {
let inviteCodePopUpViewController = InvitationCodePopUpViewController(
invitationCode: createMeetingViewModel.inviteCode.value
invitationCode: viewModel.inviteCode.value
)

setupPopUpViewController(viewController: inviteCodePopUpViewController)
setupPopUpAction(view: inviteCodePopUpViewController.rootView)
removeDismissGesture(view: inviteCodePopUpViewController.rootView)
createMeetingViewModel.createMeeting(name: createMeetingViewModel.meetingName.value)
viewModel.createMeeting(name: viewModel.meetingName.value)

DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
inviteCodePopUpViewController.rootView.setInvitationCodeText(
self.createMeetingViewModel.inviteCode.value
self.viewModel.inviteCode.value
)

self.present(inviteCodePopUpViewController, animated: true)
Expand All @@ -131,17 +131,17 @@ private extension CreateMeetingViewController {

@objc
private func copyButtonDidTap() {
UIPasteboard.general.string = createMeetingViewModel.inviteCode.value
UIPasteboard.general.string = viewModel.inviteCode.value

let finishCreateViewController = FinishCreateViewController(meetingID: createMeetingViewModel.meetingID)
let finishCreateViewController = FinishCreateViewController(meetingID: viewModel.meetingID)

navigationController?.pushViewController(finishCreateViewController, animated: true)
}

@objc
private func inviteLaterButtonDidTap() {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.7) {
let finishCreateViewController = FinishCreateViewController(meetingID: self.createMeetingViewModel.meetingID)
let finishCreateViewController = FinishCreateViewController(meetingID: self.viewModel.meetingID)

self.navigationController?.pushViewController(finishCreateViewController, animated: true)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ class CreateMeetingViewModel {

// MARK: Property

var createMeetingResponse = ObservablePattern<MakeMeetingsResponseModel?>(nil)
let isNextButtonEnabled = ObservablePattern<Bool>(false)
let meetingName = ObservablePattern<String>("")
let inviteCode = ObservablePattern<String>("")
let characterCount = ObservablePattern<String>("0/10")
let inviteCodeState = ObservablePattern<MeetingNameState>(.empty)
let createMeetingService: CreateMeetingServiceProtocol

var createMeetingResponse = ObservablePattern<MakeMeetingsResponseModel?>(nil)

private (set) var meetingID: Int = 0


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ class InviteCodeView: BaseView {


// MARK: Property

private let mainTitleLabel: UILabel = UILabel().then {
$0.setText("모임 초대 코드를\n입력해 주세요", style: .head01)
}

let inviteCodeTextField: CustomTextField = CustomTextField(
placeHolder: "모임 초대 코드를 입력해 주세요"
Expand All @@ -33,6 +29,9 @@ class InviteCodeView: BaseView {

let presentButton: CustomButton = CustomButton(title: "모임 가입하기", isEnabled: false)

private let mainTitleLabel: UILabel = UILabel().then {
$0.setText("모임 초대 코드를\n입력해 주세요", style: .head01)
}

// MARK: - Setup

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ class InviteCodeViewController: BaseViewController {

// MARK: Property

private let inviteCodeViewModel: InviteCodeViewModel

private let inviteCodeView: InviteCodeView = InviteCodeView()
private let viewModel: InviteCodeViewModel
private let rootView: InviteCodeView = InviteCodeView()


// MARK: - LifeCycle

init(viewModel: InviteCodeViewModel) {
self.inviteCodeViewModel = viewModel
self.viewModel = viewModel
super.init(nibName: nil, bundle: nil)
}

Expand All @@ -29,7 +28,7 @@ class InviteCodeViewController: BaseViewController {
}

override func loadView() {
view = inviteCodeView
view = rootView
}

override func viewDidLoad() {
Expand Down Expand Up @@ -60,21 +59,21 @@ class InviteCodeViewController: BaseViewController {
}

override func setupAction() {
inviteCodeView.inviteCodeTextField.addTarget(
rootView.inviteCodeTextField.addTarget(
self,
action: #selector(textFieldDidChange(_:)),
for: .editingChanged
)
inviteCodeView.presentButton.addTarget(
rootView.presentButton.addTarget(
self,
action: #selector(nextButtonTapped),
for: .touchUpInside
)
}

override func setupDelegate() {
inviteCodeView.inviteCodeTextField.delegate = self
inviteCodeView.inviteCodeTextField.returnKeyType = .done
rootView.inviteCodeTextField.delegate = self
rootView.inviteCodeTextField.returnKeyType = .done
}
}

Expand All @@ -83,36 +82,36 @@ class InviteCodeViewController: BaseViewController {

extension InviteCodeViewController {
private func setupBinding() {
inviteCodeViewModel.inviteCodeState.bind(with: self) { owner, state in
viewModel.inviteCodeState.bind(with: self) { owner, state in
switch state {
case .empty:
owner.inviteCodeView.inviteCodeTextField.layer.borderColor = UIColor.gray3.cgColor
owner.inviteCodeView.errorLabel.isHidden = true
owner.inviteCodeView.checkImageView.isHidden = true
owner.inviteCodeView.presentButton.isEnabled = false
owner.rootView.inviteCodeTextField.layer.borderColor = UIColor.gray3.cgColor
owner.rootView.errorLabel.isHidden = true
owner.rootView.checkImageView.isHidden = true
owner.rootView.presentButton.isEnabled = false
case .invalid:
owner.inviteCodeView.inviteCodeTextField.layer.borderColor = UIColor.mainred.cgColor
owner.inviteCodeView.errorLabel.isHidden = false
owner.inviteCodeView.checkImageView.isHidden = true
owner.inviteCodeView.presentButton.isEnabled = false
owner.rootView.inviteCodeTextField.layer.borderColor = UIColor.mainred.cgColor
owner.rootView.errorLabel.isHidden = false
owner.rootView.checkImageView.isHidden = true
owner.rootView.presentButton.isEnabled = false
case .valid:
owner.inviteCodeView.inviteCodeTextField.layer.borderColor = UIColor.maincolor.cgColor
owner.inviteCodeView.errorLabel.isHidden = true
owner.inviteCodeView.checkImageView.isHidden = true
owner.inviteCodeView.presentButton.isEnabled = true
owner.rootView.inviteCodeTextField.layer.borderColor = UIColor.maincolor.cgColor
owner.rootView.errorLabel.isHidden = true
owner.rootView.checkImageView.isHidden = true
owner.rootView.presentButton.isEnabled = true
case .success:
owner.inviteCodeView.inviteCodeTextField.layer.borderColor = UIColor.maincolor.cgColor
owner.inviteCodeView.errorLabel.isHidden = true
owner.inviteCodeView.checkImageView.isHidden = false
owner.inviteCodeView.presentButton.isEnabled = true
owner.rootView.inviteCodeTextField.layer.borderColor = UIColor.maincolor.cgColor
owner.rootView.errorLabel.isHidden = true
owner.rootView.checkImageView.isHidden = false
owner.rootView.presentButton.isEnabled = true
}
}

inviteCodeViewModel.meetingID.bind { [weak self] id in
viewModel.meetingID.bind { [weak self] id in
guard let id else { return }

DispatchQueue.main.async {
self?.inviteCodeViewModel.inviteCodeState.value = .success
self?.viewModel.inviteCodeState.value = .success
}

DispatchQueue.main.asyncAfter(deadline: .now() + 0.7) {
Expand All @@ -139,10 +138,10 @@ extension InviteCodeViewController {
}
}

inviteCodeViewModel.errorDescription.bind(with: self) { owner, error in
viewModel.errorDescription.bind(with: self) { owner, error in
DispatchQueue.main.async {
owner.inviteCodeView.errorLabel.setText(error, style: .caption02, color: .mainred)
owner.inviteCodeViewModel.inviteCodeState.value = .invalid
owner.rootView.errorLabel.setText(error, style: .caption02, color: .mainred)
owner.viewModel.inviteCodeState.value = .invalid
}
}
}
Expand All @@ -155,16 +154,16 @@ extension InviteCodeViewController {
}

@objc private func nextButtonTapped() {
inviteCodeViewModel.joinMeeting(inviteCode: inviteCodeViewModel.inviteCode.value)
viewModel.joinMeeting(inviteCode: viewModel.inviteCode.value)
}

@objc private func textFieldDidChange(_ textField: UITextField) {
inviteCodeViewModel.validateCode(textField.text ?? "")
viewModel.validateCode(textField.text ?? "")
}

@objc private func dismissKeyboard() {
view.endEditing(true)
inviteCodeView.inviteCodeTextField.layer.borderColor = UIColor.gray3.cgColor
rootView.inviteCodeTextField.layer.borderColor = UIColor.gray3.cgColor
}
}

Expand All @@ -173,19 +172,19 @@ extension InviteCodeViewController {

extension InviteCodeViewController: UITextFieldDelegate {
func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
inviteCodeView.inviteCodeTextField.layer.borderColor = UIColor.maincolor.cgColor
rootView.inviteCodeTextField.layer.borderColor = UIColor.maincolor.cgColor

return true
}

func textFieldShouldEndEditing(_ textField: UITextField) -> Bool {
switch inviteCodeViewModel.inviteCodeState.value {
switch viewModel.inviteCodeState.value {
case .empty:
inviteCodeView.inviteCodeTextField.layer.borderColor = UIColor.gray3.cgColor
rootView.inviteCodeTextField.layer.borderColor = UIColor.gray3.cgColor
case .valid, .success:
inviteCodeView.inviteCodeTextField.layer.borderColor = UIColor.maincolor.cgColor
rootView.inviteCodeTextField.layer.borderColor = UIColor.maincolor.cgColor
case .invalid:
inviteCodeView.inviteCodeTextField.layer.borderColor = UIColor.mainred.cgColor
rootView.inviteCodeTextField.layer.borderColor = UIColor.mainred.cgColor
}

return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ class PagePromiseSegmentedControl: UISegmentedControl {


// MARK: Property

private let backgroundLineView: UIView = UIView(backgroundColor: .gray2)

let selectedUnderLineView: UIView = UIView(backgroundColor: .black).then {
$0.layer.cornerRadius = 1
}

private let backgroundLineView: UIView = UIView(backgroundColor: .gray2)


// MARK: Initialize

Expand Down
Loading

0 comments on commit b5219d6

Please sign in to comment.