From 38653247b8880b410d2ea5ecc647145dec807e61 Mon Sep 17 00:00:00 2001 From: Yu Sung Date: Tue, 30 Apr 2024 19:24:17 +0900 Subject: [PATCH] =?UTF-8?q?=EC=8B=9C=EB=A6=AC=EC=A6=88=20=EC=83=81?= =?UTF-8?q?=EC=84=B8=20=EC=9E=91=ED=92=88=EC=86=8C=EA=B0=9C=20=ED=82=A4?= =?UTF-8?q?=EC=9B=8C=EB=93=9C=20-=20=EA=B8=80=EC=9E=90=EA=B0=80=202?= =?UTF-8?q?=EC=A4=84=EB=A1=9C=20=EB=B3=B4=EC=9D=B4=EA=B1=B0=EB=82=98=20?= =?UTF-8?q?=EC=9E=98=EB=A6=AC=EB=8A=94=20=EB=B2=84=EA=B7=B8=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xcshareddata/swiftpm/Package.resolved | 18 +++--- .../Detail/SeriesDetailIntroductionView.swift | 9 +-- .../UI/Component/SeriesKeywordChipView.swift | 1 + SodaLive/Sources/UI/Component/TagsView.swift | 60 +++++++++++++++++++ 4 files changed, 72 insertions(+), 16 deletions(-) create mode 100644 SodaLive/Sources/UI/Component/TagsView.swift diff --git a/SodaLive.xcworkspace/xcshareddata/swiftpm/Package.resolved b/SodaLive.xcworkspace/xcshareddata/swiftpm/Package.resolved index 75d35f0..be358da 100644 --- a/SodaLive.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/SodaLive.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -225,6 +225,15 @@ "version" : "1.22.1" } }, + { + "identity" : "swiftui-flow-layout", + "kind" : "remoteSourceControl", + "location" : "https://github.com/globulus/swiftui-flow-layout", + "state" : { + "revision" : "de7da3440c3b87ba94adfa98c698828d7746a76d", + "version" : "1.0.5" + } + }, { "identity" : "swiftui-sliders", "kind" : "remoteSourceControl", @@ -233,15 +242,6 @@ "revision" : "d5a7d856655d5c91f891c2b69d982c30fd5c7bdf", "version" : "2.1.0" } - }, - { - "identity" : "taglayoutview", - "kind" : "remoteSourceControl", - "location" : "https://github.com/yotsu12/TagLayoutView", - "state" : { - "branch" : "master", - "revision" : "815deadaca2b65edb03ec2fe25d0ce300d2eb7b3" - } } ], "version" : 2 diff --git a/SodaLive/Sources/Content/Series/Detail/SeriesDetailIntroductionView.swift b/SodaLive/Sources/Content/Series/Detail/SeriesDetailIntroductionView.swift index be0e441..59c6e78 100644 --- a/SodaLive/Sources/Content/Series/Detail/SeriesDetailIntroductionView.swift +++ b/SodaLive/Sources/Content/Series/Detail/SeriesDetailIntroductionView.swift @@ -6,7 +6,7 @@ // import SwiftUI -import TagLayoutView +import SwiftUIFlowLayout struct SeriesDetailIntroductionView: View { @@ -21,12 +21,7 @@ struct SeriesDetailIntroductionView: View { .padding(.top, 16) .padding(.horizontal, 13.3) - TagLayoutView( - seriesDetail.keywordList, - tagFont: UIFont(name: Font.medium.rawValue, size: 12)!, - padding: 5.3, - parentWidth: width - ) { + FlowLayout(mode: .scrollable, items: seriesDetail.keywordList, itemSpacing: 5.3) { SeriesKeywordChipView(keyword: $0) } .padding(.horizontal, 13.3) diff --git a/SodaLive/Sources/UI/Component/SeriesKeywordChipView.swift b/SodaLive/Sources/UI/Component/SeriesKeywordChipView.swift index 036bb95..d817d6d 100644 --- a/SodaLive/Sources/UI/Component/SeriesKeywordChipView.swift +++ b/SodaLive/Sources/UI/Component/SeriesKeywordChipView.swift @@ -19,6 +19,7 @@ struct SeriesKeywordChipView: View { .padding(.vertical, 5.3) .background(Color.gray22) .cornerRadius(26.7) + .lineLimit(1) } } diff --git a/SodaLive/Sources/UI/Component/TagsView.swift b/SodaLive/Sources/UI/Component/TagsView.swift new file mode 100644 index 0000000..3506c23 --- /dev/null +++ b/SodaLive/Sources/UI/Component/TagsView.swift @@ -0,0 +1,60 @@ +// +// TagsView.swift +// SodaLive +// +// Created by klaus on 4/30/24. +// + +import SwiftUI + +struct TagsView: View { + let items: [T] //Hashable items + var lineLimit: Int //How many lines do you want + var grouptedItems: [[T]] = [[T]]() + let cloudTagView: (T) -> V + + init(items: [T], lineLimit: Int, cloudTagView: @escaping (T) -> V) { + self.items = items + self.cloudTagView = cloudTagView + self.lineLimit = lineLimit + self.grouptedItems = self.createGroupedItems(items, lineLimit: + lineLimit) + } + + var body: some View { + ScrollView(.horizontal, showsIndicators: false) { + VStack(alignment: .leading) { + ForEach(self.grouptedItems, id: \.self) { subItems in + HStack { + ForEach(subItems, id: \.self) { word in + cloudTagView(word) + } + Spacer() + }.padding(.horizontal, 16) + } + } + } + } + + private func createGroupedItems(_ items: [T], lineLimit: Int) -> [[T]] + { + var grouptedItems: [[T]] = [[T]]() + var tempItems: [T] = [T]() + + let temp = items.count % lineLimit + let count = (items.count - temp) / lineLimit + + for word in items { + if tempItems.count < count + 1 { + tempItems.append(word) + } else { + grouptedItems.append(tempItems) + tempItems.removeAll() + tempItems.append(word) + } + } + + grouptedItems.append(tempItems) + return grouptedItems + } +}