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 + } +}