Skip to content

Commit b3a3295

Browse files
committed
Deprecate flow layouts and simplify tag lists
1 parent 364d397 commit b3a3295

File tree

8 files changed

+210
-265
lines changed

8 files changed

+210
-265
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Once a type implements ``Taggable``, it can make use of a lot of automatically i
7777

7878
### Views
7979

80-
TagKit has a bunch of tag related types, like ``TagCapsule``, ``TagList``, ``TagEditList`` and ``TagTextField``.
80+
TagKit has a couple of tag related views, like ``TagList``, ``TagEditList`` and ``TagTextField``.
8181

8282

8383

RELEASE_NOTES.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,19 @@ TagKit will use semver after 1.0.
66

77
## 0.5
88

9-
This version makes TagKit use Swift 6.
9+
This version makes TagKit use Swift 6, by removing the flow layout parts from the library.
10+
11+
The `TagList` and `TagEditList` is therefore much simpler now before, and can be used in more ways.
12+
13+
### 💡 Behavior Changes
14+
15+
* `TagList` and `TagEditList` now just lists the provided tags.
16+
* `TagList` and `TagEditList` can now be rendered in any layout container.
1017

1118
### 🗑️ Deprecated
1219

1320
* `Slugifiable` has been deprecated. Just use the `slugified` string extension instead.
21+
* `TagCapsule` has been deprecated, since it's better to just customize a regular `Text`.
1422

1523
### 💥 Breaking Changes
1624

Sources/TagKit/TagKit.docc/TagKit.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Once a type implements ``Taggable``, it can make use of a lot of automatically i
6666

6767
### Views
6868

69-
TagKit has a bunch of tag related types, like ``TagCapsule``, ``TagList``, ``TagEditList`` and ``TagTextField``.
69+
TagKit has a couple of tag related views, like ``TagList``, ``TagEditList`` and ``TagTextField``.
7070

7171

7272

@@ -95,9 +95,6 @@ TagKit is available under the MIT license.
9595

9696
### Views
9797

98-
- ``TagCapsule``
99-
- ``TagCapsuleStyle``
100-
- ``TagEditList``
10198
- ``TagList``
102-
- ``TagListContainer``
99+
- ``TagEditList``
103100
- ``TagTextField``

Sources/TagKit/Views/TagEditList.swift

Lines changed: 29 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -8,73 +8,45 @@
88

99
import SwiftUI
1010

11-
/**
12-
This view lists tags in a leading to trailing flow and lets
13-
you tap tags to add and remove them from a provided binding.
14-
15-
The view takes a list of tags and use a tag view builder to
16-
render a view for each tag. You can use any custom tag view,
17-
for instance a ``TagCapsule``.
18-
19-
The view can take a list of additional tags. Tho avoid that
20-
tags disappear from the list when you toggle them off. Make
21-
sure to use the `additionalTags` parameter to specify which
22-
tags you always want to show in the list.
23-
24-
You must specify a `container`, since this list is rendered
25-
differently depending on if it's added to a `ScrollView` or
26-
a `VerticalStack`.
27-
*/
11+
/// This view lists a collection of tags, that can be tapped
12+
/// to toggle them in the provided tags binding.
13+
///
14+
/// This view will list all tags in the provided binding, as
15+
/// well as a list of additional tags which should be listed
16+
/// even when they are not set in the binding.
17+
///
18+
/// Note that this list only renders the tag views. You must
19+
/// specify the container in which they will be rendered.
2820
public struct TagEditList<TagView: View>: View {
2921

3022
/// Create a tag edit list.
3123
///
3224
/// - Parameters:
3325
/// - tags: The items to render in the layout.
3426
/// - additionalTags: Additional tags to pick from.
35-
/// - container: The container type, by default `.scrollView`.
36-
/// - horizontalSpacing: The horizontal spacing between items.
37-
/// - verticalSpacing: The vertical spacing between items.
3827
/// - tagView: The tag view builder.
3928
public init(
4029
tags: Binding<[String]>,
4130
additionalTags: [String],
42-
container: TagListContainer = .scrollView,
43-
horizontalSpacing: CGFloat = 5,
44-
verticalSpacing: CGFloat = 5,
4531
@ViewBuilder tagView: @escaping TagViewBuilder
4632
) {
4733
self.tags = tags
4834
self.additionalTags = additionalTags
49-
self.container = container
50-
self.horizontalSpacing = horizontalSpacing
51-
self.verticalSpacing = verticalSpacing
5235
self.tagView = tagView
53-
let initialHeight: CGFloat = container == .scrollView ? .zero : .infinity
54-
_totalHeight = State(initialValue: initialHeight)
5536
}
5637

5738
private let tags: Binding<[String]>
5839
private let additionalTags: [String]
59-
private let container: TagListContainer
60-
private let horizontalSpacing: CGFloat
61-
private let verticalSpacing: CGFloat
62-
40+
6341
@ViewBuilder
6442
private let tagView: TagViewBuilder
6543

6644
/// This type defines the tag view builder for the list.
6745
public typealias TagViewBuilder = (_ tag: String, _ hasTag: Bool) -> TagView
6846

69-
@State
70-
private var totalHeight: CGFloat
71-
7247
public var body: some View {
7348
TagList(
7449
tags: allTags,
75-
container: container,
76-
horizontalSpacing: horizontalSpacing,
77-
verticalSpacing: verticalSpacing
7850
) { tag in
7951
Button(action: { toggleTag(tag) }) {
8052
tagView(tag, hasTag(tag))
@@ -124,104 +96,60 @@ private extension TagEditList {
12496

12597
struct Preview: View {
12698

127-
@State
128-
var newTag = ""
129-
130-
@State
131-
var tags = ["tag-1"]
132-
133-
@State
134-
var added: [String] = []
99+
@State var newTag = ""
100+
@State var tags = ["tag-1"]
101+
102+
let slugConfiguration = SlugConfiguration.standard
135103

136104
var body: some View {
137105
NavigationView {
138106
ScrollView {
139-
VStack(alignment: .leading, spacing: 30) {
140-
list("Standard Style", .standard, .standardSelected)
141-
list("Custom Style", .custom, .customSelected)
107+
TagEditList(
108+
tags: $tags,
109+
additionalTags: ["always-visible"]
110+
) { tag, isAdded in
111+
Text(tag.slugified())
112+
.font(.system(size: 12))
113+
.foregroundColor(.black)
114+
.padding(.horizontal, 8)
115+
.padding(.vertical, 4)
116+
.background(isAdded ? Color.green : Color.primary.opacity(0.1), in: .capsule)
142117
}
143118
.padding()
144-
145119
}
146-
// .background(
147-
// LinearGradient(
148-
// colors: [.red, .blue],
149-
// startPoint: .top,
150-
// endPoint: .bottom
151-
// )
152-
// )
153120
.toolbar {
154121
ToolbarItem {
155122
HStack {
156123
TagTextField(
157124
text: $newTag,
158-
placeholder: "Add new tag"
125+
placeholder: "Add new tag",
126+
configuration: slugConfiguration
159127
)
160128
#if os(iOS)
161129
.autocorrectionDisabled()
162130
.textFieldStyle(.roundedBorder)
163131
#endif
164132
Button("Add") {
165-
addTag(tag: newTag)
133+
addNewTag(tag: newTag)
166134
}
167135
.disabled(newTag.isEmpty)
168136
}
169137
}
170138
}
171139
}
172140
}
173-
174-
private func list(
175-
_ title: String,
176-
_ style: TagCapsuleStyle,
177-
_ selected: TagCapsuleStyle
178-
) -> some View {
179-
VStack(alignment: .leading) {
180-
Text(title)
181-
.font(.footnote)
182-
183-
TagEditList(
184-
tags: $tags,
185-
additionalTags: ["tag-1", "tag-2", "tag-3"] + added
186-
) { tag, hasTag in
187-
TagCapsule(tag)
188-
.tagCapsuleStyle(hasTag ? selected : style)
189-
}
190-
}
191-
}
192141

193-
private func addTag(
142+
private func addNewTag(
194143
tag: String,
195144
selected: Bool = true
196145
) {
197-
let slug = tag.slugified()
146+
let slug = tag.slugified(with: slugConfiguration)
198147
if selected {
199148
tags.append(slug)
200149
}
201-
added.append(slug)
202150
newTag = ""
203151
}
204152
}
205153

206154
return Preview()
207155
}
208-
209-
private extension TagCapsuleStyle {
210-
211-
static var custom: TagCapsuleStyle {
212-
.init(
213-
foregroundColor: .black,
214-
backgroundColor: .red,
215-
border: .init(width: 4)
216-
)
217-
}
218-
219-
static var customSelected: TagCapsuleStyle {
220-
.init(
221-
foregroundColor: .black,
222-
backgroundColor: .red,
223-
border: .init(width: 4),
224-
shadow: .standardSelected
225-
)
226-
}
227-
}

0 commit comments

Comments
 (0)