Skip to content

Commit ee052d8

Browse files
committed
[#465] 버튼 누를때 뷰 변경
1 parent 958bd19 commit ee052d8

File tree

4 files changed

+74
-58
lines changed

4 files changed

+74
-58
lines changed

DesignSystem/Views/DynamicCellLayout.swift

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import SwiftUI
1111
Cell들의 폭의 반응하여 List를 만드는 구조체
1212
*/
1313
struct DynamicCellLayout<Data: RandomAccessCollection>: View where Data.Element: DynamicCell {
14-
// @EnvironmentObject var tagViewModel: TagViewModel
1514
let data: Data
1615
let screenWidth: CGFloat
1716
let selectedTags: [String]

Presentation/Home/TagSearch/SelectedTagCell.swift

+11-8
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,27 @@ import SwiftUI
1010
struct SelectedTagCell<Tag: DynamicCell>: View {
1111
let tag: Tag
1212
let action: () -> Void
13+
let isBtnTapped: Bool
1314
var body: some View {
1415
HStack {
1516
Text(tag.name)
1617
.reazyFont(.text1)
17-
.foregroundStyle(.gray300)
18-
Button {
19-
action()
20-
} label: {
21-
Image(systemName: "xmark")
22-
.font(.system(size: 11))
23-
.foregroundStyle(.gray300)
18+
.foregroundStyle(isBtnTapped ? .gray300 : .gray800)
19+
if isBtnTapped {
20+
Button {
21+
action()
22+
} label: {
23+
Image(systemName: "xmark")
24+
.font(.system(size: 11))
25+
.foregroundStyle(.gray300)
26+
}
2427
}
2528
}
2629
.frame(height: 28)
2730
.padding(.horizontal, 8)
2831
.background {
2932
RoundedRectangle(cornerRadius: 4)
30-
.foregroundStyle(.point4)
33+
.foregroundStyle(isBtnTapped ? .point4 : .primary3)
3134
}
3235
}
3336
}

Presentation/Home/TagSearch/TagView.swift

+55-48
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@ struct TagView: View {
2424
} else {
2525
TagLEmptyView()
2626
}
27+
28+
Spacer()
29+
30+
Button(action: {
31+
withAnimation {
32+
tagViewModel.isBtnTapped.toggle()
33+
}
34+
}, label: {
35+
Image(systemName: tagViewModel.isBtnTapped ? "chevron.down" : "chevron.right")
36+
.font(.system(size: 16))
37+
.foregroundStyle(.gray600)
38+
})
39+
.frame(alignment: .trailing)
2740
}
2841
.padding(.horizontal, 20)
2942
.padding(.vertical, 15)
@@ -33,51 +46,52 @@ struct TagView: View {
3346
.fill(.gray100)
3447
.stroke(Color.gray400, lineWidth: 1)
3548
)
36-
37-
VStack {
38-
Group {
39-
if tagViewModel.isTagExist {
40-
TagListView(selectedTags: $tagViewModel.selectedTags, toggleTag: tagViewModel.tagTapped)
41-
} else {
42-
Text("아직 태그를 만들지 않았어요")
43-
.reazyFont(.text1)
44-
.foregroundStyle(.gray550)
49+
if tagViewModel.isBtnTapped {
50+
VStack {
51+
Group {
52+
if tagViewModel.isTagExist {
53+
TagListView(selectedTags: $tagViewModel.selectedTags, toggleTag: tagViewModel.tagTapped)
54+
} else {
55+
Text("아직 태그를 만들지 않았어요")
56+
.reazyFont(.text1)
57+
.foregroundStyle(.gray550)
58+
}
4559
}
46-
}
47-
.frame(minHeight: geometry.size.height * 0.35)
48-
49-
// 편집 버튼
50-
HStack(spacing: 0) {
51-
Spacer()
52-
if tagViewModel.isEditMode {
53-
Button {
54-
withAnimation {
55-
tagViewModel.isEditMode = false
60+
.frame(minHeight: geometry.size.height * 0.35)
61+
62+
// 편집 버튼
63+
HStack(spacing: 0) {
64+
Spacer()
65+
if tagViewModel.isEditMode {
66+
Button {
67+
withAnimation {
68+
tagViewModel.isEditMode = false
69+
}
70+
} label: {
71+
Text("완료")
72+
.reazyFont(.button1)
73+
.foregroundColor(.primary1)
74+
.padding(.trailing, 24)
75+
.padding(.bottom, 20)
5676
}
57-
} label: {
58-
Text("완료")
59-
.reazyFont(.button1)
60-
.foregroundColor(.primary1)
61-
.padding(.trailing, 24)
62-
.padding(.bottom, 20)
77+
} else {
78+
EllipsisView(ellipsisAction: {
79+
withAnimation {
80+
tagViewModel.popover.toggle()
81+
}
82+
})
83+
.matchedGeometryEffect(id: "popover",
84+
in: nsPopover,
85+
anchor: .topTrailing)
6386
}
64-
} else {
65-
EllipsisView(ellipsisAction: {
66-
withAnimation {
67-
tagViewModel.popover.toggle()
68-
}
69-
})
70-
.matchedGeometryEffect(id: "popover",
71-
in: nsPopover,
72-
anchor: .topTrailing)
7387
}
7488
}
89+
.frame(maxWidth: .infinity,maxHeight: geometry.size.height * 0.4)
90+
.background(
91+
RoundedRectangle(cornerRadius: 12)
92+
.fill(.gray200)
93+
)
7594
}
76-
.frame(maxWidth: .infinity,maxHeight: geometry.size.height * 0.4)
77-
.background(
78-
RoundedRectangle(cornerRadius: 12)
79-
.fill(.gray200)
80-
)
8195
}
8296
.padding([.top, .horizontal], 20)
8397
}
@@ -102,14 +116,7 @@ struct TagLEmptyView: View {
102116
Text("태그로 원하는 논문을 찾아보세요")
103117
.reazyFont(.button1)
104118
.foregroundStyle(.gray550)
105-
Spacer()
106-
Button(action: {
107-
108-
}, label: {
109-
Image(systemName: "chevron.down")
110-
.font(.system(size: 16))
111-
.foregroundStyle(.gray600)
112-
})
119+
// Spacer()
113120
}
114121
}
115122

@@ -125,7 +132,7 @@ struct SelectedTagView: View {
125132
ForEach(selectedTags.map { Tag(name: $0) }, id: \.id) { tag in
126133
SelectedTagCell(tag: tag, action: {
127134
toggleTag(tag.name)
128-
})
135+
}, isBtnTapped: tagViewModel.isBtnTapped)
129136
}
130137
}
131138
}

Presentation/Home/TagSearch/TagViewModel.swift

+8-1
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,21 @@ class TagViewModel: ObservableObject {
1313

1414
private let tagViewUseCase: TagViewUseCase
1515
// MARK: - [부리] tags에 사용자가 만든 태그들 다 저장
16-
@Published public var tags: [Tag] = []
16+
@Published public var tags: [Tag] = [] {
17+
didSet {
18+
selectedTags = selectedTags.filter { tagName in
19+
tags.contains(where: { $0.name == tagName })
20+
}
21+
}
22+
}
1723
@Published public var selectedTags: [String] = [] {
1824
didSet {
1925
isTagSelected = !selectedTags.isEmpty
2026
}
2127
}
2228
@Published public private(set) var isTagExist: Bool = false
2329
@Published public var isTagSelected: Bool = false
30+
@Published public var isBtnTapped: Bool = false
2431
@Published public var isEditMode: Bool = false
2532
@Published public var popover: Bool = false
2633
@Published public var createTag: Bool = false

0 commit comments

Comments
 (0)