Skip to content

Commit

Permalink
feat/#157 모임 생성 텍스트필드 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
youz2me committed Jul 12, 2024
1 parent ec4185a commit 2b41213
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 2 deletions.
12 changes: 12 additions & 0 deletions KkuMulKum.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
DD3072242C3C0EB200416D9F /* MyPromiseReadyInfoRequestModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD3072232C3C0EB200416D9F /* MyPromiseReadyInfoRequestModel.swift */; };
DD3072262C3C0F0B00416D9F /* PromiseLateInfoResponseModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD3072252C3C0F0B00416D9F /* PromiseLateInfoResponseModel.swift */; };
DD3072282C3C104D00416D9F /* ArrivalCompletionResponseModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD3072272C3C104D00416D9F /* ArrivalCompletionResponseModel.swift */; };
DD3976682C41769400E2A4C4 /* CreateGroupViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD3976672C41769400E2A4C4 /* CreateGroupViewModel.swift */; };
DD4393762C412F4500EC1799 /* InviteCodeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD43936D2C412F4500EC1799 /* InviteCodeView.swift */; };
DD4393772C412F4500EC1799 /* CreateGroupView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD43936E2C412F4500EC1799 /* CreateGroupView.swift */; };
DD4393782C412F4500EC1799 /* CheckInviteCodeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD43936F2C412F4500EC1799 /* CheckInviteCodeView.swift */; };
Expand Down Expand Up @@ -195,6 +196,7 @@
DD3072232C3C0EB200416D9F /* MyPromiseReadyInfoRequestModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyPromiseReadyInfoRequestModel.swift; sourceTree = "<group>"; };
DD3072252C3C0F0B00416D9F /* PromiseLateInfoResponseModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PromiseLateInfoResponseModel.swift; sourceTree = "<group>"; };
DD3072272C3C104D00416D9F /* ArrivalCompletionResponseModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArrivalCompletionResponseModel.swift; sourceTree = "<group>"; };
DD3976672C41769400E2A4C4 /* CreateGroupViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreateGroupViewModel.swift; sourceTree = "<group>"; };
DD43936D2C412F4500EC1799 /* InviteCodeView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InviteCodeView.swift; sourceTree = "<group>"; };
DD43936E2C412F4500EC1799 /* CreateGroupView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CreateGroupView.swift; sourceTree = "<group>"; };
DD43936F2C412F4500EC1799 /* CheckInviteCodeView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CheckInviteCodeView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -476,6 +478,14 @@
path = KkuMulKum;
sourceTree = "<group>";
};
DD3976692C41769900E2A4C4 /* ViewModel */ = {
isa = PBXGroup;
children = (
DD3976672C41769400E2A4C4 /* CreateGroupViewModel.swift */,
);
path = ViewModel;
sourceTree = "<group>";
};
DD43936B2C412F4500EC1799 /* GroupCreate */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -536,6 +546,7 @@
children = (
DD4393852C41632100EC1799 /* ViewController */,
DD4393862C41632800EC1799 /* View */,
DD3976692C41769900E2A4C4 /* ViewModel */,
);
path = CreateGroup;
sourceTree = "<group>";
Expand Down Expand Up @@ -1199,6 +1210,7 @@
DE32D1D22C3BF703006848DF /* LoginUserResponseModel.swift in Sources */,
DE9E18892C3BC91000DB76B4 /* ResponseBodyDTO.swift in Sources */,
DD931B6B2C3D9EBB00526452 /* ReadyStatusView.swift in Sources */,
DD3976682C41769400E2A4C4 /* CreateGroupViewModel.swift in Sources */,
DD3072202C3C0D4500416D9F /* MyReadyStatusResponseModel.swift in Sources */,
DD3072282C3C104D00416D9F /* ArrivalCompletionResponseModel.swift in Sources */,
DD931B6E2C3DA27F00526452 /* ParticipantCollectionViewCell.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,50 @@ class CreateGroupView: BaseView {
$0.setText("모임 이름을\n입력해 주세요", style: .head01)
}

private let inviteCodeTextField: CustomTextField = CustomTextField(
let nameTextField: CustomTextField = CustomTextField(
placeHolder: "모임 이름을 입력해 주세요"
)

let presentButton: CustomButton = CustomButton(title: "다음", isEnabled: false)
let characterLabel: UILabel = UILabel().then {
$0.setText("0/10", style: .body06, color: .gray3)
}

let presentButton: CustomButton = CustomButton(
title: "다음",
isEnabled: false
)

override func setupView() {
addSubviews(
mainTitleLabel,
nameTextField,
characterLabel,
presentButton
)
}

override func setupAutoLayout() {
mainTitleLabel.snp.makeConstraints {
$0.top.equalTo(safeAreaLayoutGuide).offset(32)
$0.leading.equalToSuperview().offset(20)
}

nameTextField.snp.makeConstraints {
$0.top.equalTo(mainTitleLabel.snp.bottom).offset(24)
$0.width.equalTo(CustomTextField.defaultWidth)
$0.height.equalTo(CustomTextField.defaultHeight)
$0.leading.equalTo(mainTitleLabel)
}

characterLabel.snp.makeConstraints {
$0.centerY.equalTo(nameTextField)
$0.trailing.equalTo(nameTextField.snp.trailing).inset(12)
}

presentButton.snp.makeConstraints {
$0.bottom.equalToSuperview().inset(50)
$0.horizontalEdges.equalToSuperview().inset(14)
$0.height.equalTo(Screen.height(50))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,67 @@
import UIKit

class CreateGroupViewController: BaseViewController {
private let createGroupViewModel: CreateGroupViewModel = CreateGroupViewModel()

private let createGroupView: CreateGroupView = CreateGroupView()

override func loadView() {
view = createGroupView
}

override func viewDidLoad() {
super.viewDidLoad()

setupBinding()
setupActions()
setupTapGesture()
}

override func setupView() {
setupNavigationBarTitle(with: "내 모임 추가하기")
setupNavigationBarBackButton()
}

private func setupBinding() {
createGroupViewModel.inviteCodeState.bind(with: self) { owner, state in
switch state {
case .empty, .invalid:
self.createGroupView.presentButton.isEnabled = false
case .valid:
self.createGroupView.presentButton.isEnabled = true
}

self.createGroupViewModel.characterCount.bind(with: self) { owner, count in
self.createGroupView.characterLabel.text = count
}
}
}

private func setupActions() {
createGroupView.nameTextField.addTarget(self, action: #selector(textFieldDidChange(_:)), for: .editingChanged)
createGroupView.presentButton.addTarget(self, action: #selector(presentButtonDidTapped), for: .touchUpInside)
}

private func setupTapGesture() {
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(dismissKeyboard))
view.addGestureRecognizer(tapGesture)
}

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

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

@objc private func presentButtonDidTapped() {
// TODO: 서버 연결해서 초대 코드 받아올 수 있게 처리
let inviteCodePopUpViewController = InvitationCodePopUpViewController(invitationCode: createGroupViewModel.inviteCode.value)

inviteCodePopUpViewController.modalPresentationStyle = .fullScreen

present(inviteCodePopUpViewController, animated: true, completion: nil)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// CreateGroupViewModel.swift
// KkuMulKum
//
// Created by YOUJIM on 7/12/24.
//

import Foundation

enum GroupNameState {
case empty
case valid
case invalid
}

class CreateGroupViewModel {
let groupName = ObservablePattern<String>("")
let inviteCodeState = ObservablePattern<GroupNameState>(.empty)
let inviteCode = ObservablePattern<String>("")
let isNextButtonEnabled = ObservablePattern<Bool>(false)
let characterCount = ObservablePattern<String>("0/5")

func validateName(_ name: String) {
groupName.value = name
characterCount.value = "\(name.count)/10"

if name.isEmpty {
inviteCodeState.value = .empty
isNextButtonEnabled.value = false
} else if name.count > 10 {
inviteCodeState.value = .invalid
isNextButtonEnabled.value = false
} else {
inviteCodeState.value = .valid
isNextButtonEnabled.value = true
}
}
}

0 comments on commit 2b41213

Please sign in to comment.