Skip to content

Commit

Permalink
#168 feat: 태그 추가 시 적절한 UI 형태로 반환
Browse files Browse the repository at this point in the history
  • Loading branch information
LEEYOONJONG committed Dec 7, 2022
1 parent 456dcf0 commit eb43ef0
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
4 changes: 4 additions & 0 deletions Segno/Segno.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
7940FB33292E065F00276EFC /* DiaryDetailUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7940FB32292E065F00276EFC /* DiaryDetailUseCase.swift */; };
79767E64293E2A1200E489DD /* DiaryDeleteEndpoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = 79767E63293E2A1200E489DD /* DiaryDeleteEndpoint.swift */; };
98003E0E293F20F6009FBC35 /* DarkModeManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98003E0D293F20F6009FBC35 /* DarkModeManager.swift */; };
98138D292940B00900D2CEDF /* DeleteTapGestureRecognizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98138D282940B00900D2CEDF /* DeleteTapGestureRecognizer.swift */; };
9825F41B29377875005F2163 /* ChangeNicknameUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9825F41A29377875005F2163 /* ChangeNicknameUseCase.swift */; };
9825F41D29377ACF005F2163 /* SettingsRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9825F41C29377ACF005F2163 /* SettingsRepository.swift */; };
982A2A472924AE74006F6ACD /* UserDefaultsKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 982A2A462924AE74006F6ACD /* UserDefaultsKey.swift */; };
Expand Down Expand Up @@ -170,6 +171,7 @@
7940FB32292E065F00276EFC /* DiaryDetailUseCase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DiaryDetailUseCase.swift; sourceTree = "<group>"; };
79767E63293E2A1200E489DD /* DiaryDeleteEndpoint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiaryDeleteEndpoint.swift; sourceTree = "<group>"; };
98003E0D293F20F6009FBC35 /* DarkModeManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DarkModeManager.swift; sourceTree = "<group>"; };
98138D282940B00900D2CEDF /* DeleteTapGestureRecognizer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeleteTapGestureRecognizer.swift; sourceTree = "<group>"; };
9825F41A29377875005F2163 /* ChangeNicknameUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChangeNicknameUseCase.swift; sourceTree = "<group>"; };
9825F41C29377ACF005F2163 /* SettingsRepository.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsRepository.swift; sourceTree = "<group>"; };
982A2A462924AE74006F6ACD /* UserDefaultsKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserDefaultsKey.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -509,6 +511,7 @@
isa = PBXGroup;
children = (
9894EAF729375281005F2B15 /* DarkMode.swift */,
98138D282940B00900D2CEDF /* DeleteTapGestureRecognizer.swift */,
);
path = Utility;
sourceTree = "<group>";
Expand Down Expand Up @@ -602,6 +605,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
98138D292940B00900D2CEDF /* DeleteTapGestureRecognizer.swift in Sources */,
98F5AD2A292DDDEB00E53E25 /* LocationContentView.swift in Sources */,
791529DE29333D40005A8DDB /* ImageEndpoint.swift in Sources */,
4F4E0D3E2924B925005ABA8F /* LoginRepository.swift in Sources */,
Expand Down
13 changes: 13 additions & 0 deletions Segno/Segno/Presentation/Utility/DeleteTapGestureRecognizer.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// DeleteTapGestureRecognizer.swift
// Segno
//
// Created by YOONJONG on 2022/12/07.
//

import UIKit

class DeleteGestureRecognizer: UITapGestureRecognizer {
var title: String?
}

4 changes: 2 additions & 2 deletions Segno/Segno/Presentation/View/TagView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final class TagView: UIView {
static let cornerRadius: CGFloat = 15
}

private lazy var tagLabel: UILabel = {
lazy var tagLabel: UILabel = {
let label = UILabel()
label.font = .appFont(.surround, size: Metric.tagFontSize)
label.textColor = .appColor(.white)
Expand All @@ -34,7 +34,7 @@ final class TagView: UIView {

private func setupLayout(tagTitle: String) {
addSubview(tagLabel)
backgroundColor = .appColor(.color3)
backgroundColor = .appColor(.color4)
layer.cornerRadius = Metric.cornerRadius

tagLabel.text = tagTitle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ final class DiaryEditViewController: UIViewController {

let viewModel: DiaryEditViewModel
private var disposeBag = DisposeBag()
private var tags: [String] = []

private lazy var mainScrollView: UIScrollView = {
let scrollView = UIScrollView()
scrollView.keyboardDismissMode = .onDrag
scrollView.backgroundColor = .red
return scrollView
}()

Expand Down Expand Up @@ -104,6 +104,7 @@ final class DiaryEditViewController: UIViewController {

private lazy var tagScrollView: UIScrollView = {
let scrollView = UIScrollView()
scrollView.showsHorizontalScrollIndicator = false
return scrollView
}()

Expand Down Expand Up @@ -445,14 +446,36 @@ extension DiaryEditViewController: UIImagePickerControllerDelegate, UINavigation

extension DiaryEditViewController: UITextFieldDelegate {
func textFieldShouldReturn(_ textField: UITextField) -> Bool {

if textField == tagTextField {
print("입력된 태그 : ", tagTextField.text)
guard let tagText = tagTextField.text, !tagText.isEmpty, !tags.contains(tagText) else {
return false
}
let tagView = TagView(tagTitle: tagText)
let deleteGesture = DeleteGestureRecognizer(target: self, action: #selector(deleteTagView))
deleteGesture.title = tagText
tagView.addGestureRecognizer(deleteGesture)

tags.append(tagText)
tagStackView.addArrangedSubview(tagView)
tagTextField.text = ""
}
return true
}

@objc func deleteTagView(sender: DeleteGestureRecognizer) {
guard let tagTitle = sender.title else { return }
let tagViews = tagStackView.arrangedSubviews
.compactMap { $0 as? TagView }
.filter { $0.tagLabel.text == tagTitle }
guard let tagView = tagViews.first else { return }

if let index = tags.firstIndex(of: tagTitle) {
tags.remove(at: index)
}

tagStackView.removeArrangedSubview(tagView)
tagView.removeFromSuperview()
}
}

#if canImport(SwiftUI) && DEBUG
Expand Down

0 comments on commit eb43ef0

Please sign in to comment.