-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Design] 태그뷰 디자인하기 #470
base: develop
Are you sure you want to change the base?
[Design] 태그뷰 디자인하기 #470
Changes from 28 commits
c8c935b
a55bcb5
f2950c1
2b93b4b
db66410
69226ff
bb2f3ab
b7275de
b44aee7
43668d7
080f551
2b4bdc0
68c65cf
ed6c433
bdfa55c
df81395
01b678b
833e753
58d7941
091334b
523f8f0
7622f06
258df59
21d2912
ad11f96
840f41d
958bd19
ee052d8
83bfc20
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,25 +12,29 @@ import SwiftUI | |
*/ | ||
struct DynamicCellLayout<Data: RandomAccessCollection>: View where Data.Element: DynamicCell { | ||
let data: Data | ||
let action: (String) -> Void | ||
let screenWidth: CGFloat | ||
let selectedTags: [String] | ||
|
||
let isMultiSelectable: Bool // 여러 셀 선택 가능 | ||
let isEditMode: Bool // x마크 | ||
|
||
let selectAction: (String) -> Void | ||
let deleteAction: (UUID) -> Void | ||
|
||
var body: some View { | ||
generateLayout(items: data) | ||
} | ||
|
||
private func generateLayout(items: Data) -> some View { | ||
let screenWidth = UIScreen.main.bounds.width | ||
|
||
var currentWidth: CGFloat = 0 | ||
var currentArrays = [Data.Element]() | ||
|
||
var resultRows = [[Data.Element]]() | ||
|
||
|
||
for (index, item) in items.enumerated() { | ||
let itemWidth = item.getCellWidth() | ||
|
||
if currentWidth + itemWidth >= screenWidth { | ||
let itemWidth = item.itemWidth(isEditMode: isEditMode) | ||
if currentWidth + itemWidth + 10 >= screenWidth { | ||
Comment on lines
+36
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 셀 너비 계산할때 패딩값때문에 약간 오차가 생기는 거 같아서 넣었습니다! |
||
resultRows.append(currentArrays) | ||
currentArrays.removeAll() | ||
currentWidth = 0 | ||
|
@@ -42,20 +46,24 @@ struct DynamicCellLayout<Data: RandomAccessCollection>: View where Data.Element: | |
break | ||
} | ||
|
||
currentWidth += itemWidth | ||
currentWidth += itemWidth + 20 | ||
currentArrays.append(item) | ||
} | ||
|
||
return VStack(alignment: .leading) { | ||
ForEach(resultRows, id: \.self) { row in | ||
HStack { | ||
HStack(spacing: 10) { | ||
ForEach(row) { tag in | ||
PDFTagCell(tag: tag) { | ||
action(tag.name) | ||
} | ||
PDFTagCell(isMultiSelectable: isMultiSelectable, | ||
isEditMode: isEditMode, | ||
selectedTags: selectedTags, | ||
tag: tag, | ||
selectAction: {selectAction(tag.name)}, | ||
deleteAction: {deleteAction(tag.id)} | ||
) | ||
} | ||
} | ||
} | ||
.padding(.bottom, 10) | ||
} | ||
} | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ellipsis 버튼 재사용이 많을 거 같아서 무니 코드 따로 분리해뒀어요 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// | ||
// Component.swift | ||
// Reazy | ||
// | ||
// Created by 김예림 on 2/17/25. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct EllipsisView: View { | ||
let ellipsisAction: () -> Void | ||
|
||
var body: some View { | ||
VStack { | ||
Spacer() | ||
|
||
Button { | ||
ellipsisAction() | ||
} label: { | ||
Image(systemName: "ellipsis.circle") | ||
.font(.system(size: 24)) | ||
.foregroundStyle(.gray550) | ||
} | ||
.padding(.trailing, 24) | ||
.padding(.bottom, 20) | ||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,10 @@ protocol DynamicCell: Hashable, Identifiable { | |
|
||
func getCellWidth() -> CGFloat | ||
} | ||
|
||
extension DynamicCell { | ||
func itemWidth(isEditMode: Bool) -> CGFloat { | ||
let additionalPadding: CGFloat = isEditMode ? 40 : 16 | ||
return getCellWidth() + additionalPadding | ||
} | ||
} | ||
Comment on lines
+18
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 편집모드일 때, x버튼이 생기면서,,, 셀 너비 값 계산할 때 오차 방지를 위해 추가했습니다. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// TagViewUseCase.swift | ||
// Reazy | ||
// | ||
// Created by 김예림 on 2/17/25. | ||
// | ||
|
||
import Foundation | ||
|
||
protocol TagViewUseCase { | ||
//TODO: - 태그 저장, 수정, 삭제 | ||
} | ||
|
||
class DefaultTagViewUseCase: TagViewUseCase { | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>API_KEY</key> | ||
<string>AIzaSyAT_wmkbWRbdvZJFiARSLRTquTXlyFFTxI</string> | ||
<key>GCM_SENDER_ID</key> | ||
<string>309584491328</string> | ||
<key>PLIST_VERSION</key> | ||
<string>1</string> | ||
<key>BUNDLE_ID</key> | ||
<string>com.chillin.reazy</string> | ||
<key>PROJECT_ID</key> | ||
<string>reazy-924ee</string> | ||
<key>STORAGE_BUCKET</key> | ||
<string>reazy-924ee.firebasestorage.app</string> | ||
<key>IS_ADS_ENABLED</key> | ||
<false></false> | ||
<key>IS_ANALYTICS_ENABLED</key> | ||
<false></false> | ||
<key>IS_APPINVITE_ENABLED</key> | ||
<true></true> | ||
<key>IS_GCM_ENABLED</key> | ||
<true></true> | ||
<key>IS_SIGNIN_ENABLED</key> | ||
<true></true> | ||
<key>GOOGLE_APP_ID</key> | ||
<string>1:309584491328:ios:cb4ebfa2ccbff0c08240a5</string> | ||
</dict> | ||
</plist> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,24 +9,50 @@ import SwiftUI | |
|
||
|
||
struct PDFTagCell<Tag: DynamicCell>: View { | ||
var isSelected: Bool { | ||
return isMultiSelectable && selectedTags.contains(tag.name) | ||
} | ||
@State var isAlertPresented: Bool = false | ||
let isMultiSelectable: Bool // 멀티선택 가능 여부 | ||
let isEditMode: Bool // 편집 가능 여부 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isMultiSelectable : 태그셀을 멀티 선택이 가능한지 구분해 searchView와 tagView에서의 셀 기능을 구별해두었어요. isEditMode : 위와 마찬가지로 태그를 편집(=삭제) 가능 여부를 구분합니다 |
||
|
||
let selectedTags: [String] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이걸 어떻게 연결할까 계속 고민했는데 ..ㅜ var isSelected: Bool {
return isMultiSelectable && selectedTags.contains(tag.name)
} 근데 이렇게 하니까 selectedTags가 필요없는 다른 뷰에서는 얘를 빈배열로 비워두어야 해서 흠.. 이 방식이 괜찮은지 고민이 됩니당 |
||
let tag: Tag | ||
|
||
let action: () -> Void | ||
let selectAction: () -> Void | ||
let deleteAction: () -> Void | ||
Comment on lines
+22
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 원래는 action 하나만 있었는데, |
||
|
||
var body: some View { | ||
Button { | ||
action() | ||
selectAction() | ||
} label: { | ||
// TODO: 태그 title | ||
Text(tag.name) | ||
.reazyFont(.h3) | ||
.foregroundStyle(.gray800) | ||
.frame(height: 24) | ||
.padding(.horizontal, 8) | ||
.background { | ||
RoundedRectangle(cornerRadius: 4) | ||
.foregroundStyle(.primary3) | ||
HStack(spacing: 8) { | ||
Text(tag.name) | ||
.reazyFont(isMultiSelectable ? .body1 : .h3) | ||
.foregroundStyle(isSelected ? .gray300 : .gray800) | ||
.frame(width: tag.getCellWidth()) | ||
if isEditMode { | ||
Button { | ||
isAlertPresented = true | ||
} label: { | ||
Image(systemName: "x.circle.fill") | ||
.foregroundStyle(.gray700) | ||
.font(.system(size: 12)) | ||
} | ||
.alert("“\(tag.name)”\n태그를 삭제하시겠습니까?\n해당 태그가 달린 모든 논문에서도 삭제됩니다.", isPresented: $isAlertPresented) { | ||
Button("삭제", role: .destructive, action: { | ||
deleteAction() | ||
}) | ||
} | ||
} | ||
} | ||
.padding(.horizontal, 8) | ||
.frame(height: 24) | ||
.background { | ||
RoundedRectangle(cornerRadius: 4) | ||
.foregroundStyle(isSelected ? .point4 : .primary3) | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
screenWidth
: 이건 무니가UIScreen.main.bounds.width
값을 디폴트로 설정해 두었는데, 제가 활용하려는 뷰에서는 조정이 필요해서 넣었어요!