Skip to content

Commit 186ce51

Browse files
authored
Add new properties. Replace single padding value to horizontal/vertical. Fix unused height property and put paddings in correct place (label) (#5)
1 parent 81f986a commit 186ce51

File tree

3 files changed

+41
-34
lines changed

3 files changed

+41
-34
lines changed

Example/PillPickerViewExample/PillPickerViewExample.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@ struct ContentView: View {
5555
.tag(1)
5656
.navigationTitle("Static pills")
5757

58-
/// Example view where pills wrap to new line and only occupy
5958
/// Set the limit for the number of pills that can be selected, and configure the appropriate options for the disabled state.
60-
6159
ExampleBuilder(selectedItems: $selectedGenres, content: {
6260
PillPickerView(items: genres, selectedPills: $selectedGenres, maxSelectablePills: 5)
6361
.pillStackStyle(.wrap)

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Instantiate a PillPickerView by providing the necessary parameters, such as the
102102
PillPickerView(
103103
items: yourItemList,
104104
selectedPills: $selectedPills,
105-
maxSelectablePill : 5 // Optional Property
105+
maxSelectablePills : 5 // Optional Property
106106
)
107107
```
108108

@@ -151,7 +151,7 @@ You can customize the appearance of the pills by chaining the available modifier
151151
PillPickerView(
152152
items: yourItemList,
153153
selectedPills: $selectedPills,
154-
maxSelectablePill : 5
154+
maxSelectablePills : 5
155155
)
156156
.pillFont(.system(size: 16, weight: .semibold))
157157
.pillSelectedForegroundColor(.white)
@@ -222,11 +222,11 @@ To change the foreground color of a not selected and selected pill, respectively
222222

223223
<br>
224224

225-
The height and width of the pills can also be set, but width will be treated as the minimum width of the pills
225+
The height and width of the pills can also be set, but they will be treated as the minimum width of each pill
226226

227227
```swift
228228
.pillMinWidth(20)
229-
.pillHeight(10)
229+
.pillMinHeight(10)
230230
```
231231

232232
<br>
@@ -258,15 +258,16 @@ You can also change the animation used when a pill is pressed or wrapped to a ne
258258

259259
<br>
260260

261-
Padding can also be applied
261+
Padding can also be applied horizontally or vertically
262262

263263
```swift
264-
.pillPadding(10)
264+
.pillPaddingHorizontal(10)
265+
.pillPaddingVertical(10)
265266
```
266267

267268
<br>
268269

269-
If maxSelectablePill is set you can adjust the disabled state colors
270+
If maxSelectablePills is set you can adjust the disabled state colors
270271

271272
```swift
272273
.pillDisabledBackgroundColor(.gray.opacity(0.2))

Sources/PillPickerView.swift

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public struct PillOptions {
3535
public var minWidth: CGFloat = 50
3636

3737
/// Height of the pill
38-
public var height: CGFloat = 15
38+
public var minHeight: CGFloat = 15
3939

4040
/// Radius of the enclosing view of each pill
4141
public var cornerRadius: CGFloat = 40
@@ -54,8 +54,11 @@ public struct PillOptions {
5454
/// Foreground color of a pill when it is not selected
5555
public var normalForegroundColor: Color = .white
5656

57-
/// Padding of elements inside PillItem
58-
public var padding: CGFloat = 2.5 // -> Custom changed
57+
/// Vertical padding of content inside a pill
58+
public var verticalPadding: CGFloat = 7.5
59+
60+
/// Vertical padding of content inside a pill
61+
public var horizontalPadding: CGFloat = 7.5
5962

6063
/// Whether pills should wrap to new line or not
6164
public var stackStyle: StackStyle = StackStyle.noWrap
@@ -139,18 +142,18 @@ public struct PillPickerView<T: Pill>: View {
139142
public extension PillPickerView {
140143

141144
/// Set the background color for each pill when disabled
142-
func pillDisabledBackgroundColor(_ value: Color) -> PillPickerView {
143-
var view = self
144-
view.options.disabledBackgroundColor = value
145-
return view
146-
}
145+
func pillDisabledBackgroundColor(_ value: Color) -> PillPickerView {
146+
var view = self
147+
view.options.disabledBackgroundColor = value
148+
return view
149+
}
147150

148-
/// Set the foreground color for the title and icon in each pill when disabled
149-
func pillDisabledForegroundColor(_ value: Color) -> PillPickerView {
150-
var view = self
151-
view.options.disabledForegroundColor = value
152-
return view
153-
}
151+
/// Set the foreground color for the title and icon in each pill when disabled
152+
func pillDisabledForegroundColor(_ value: Color) -> PillPickerView {
153+
var view = self
154+
view.options.disabledForegroundColor = value
155+
return view
156+
}
154157

155158
/// The foreground color used for the title
156159
/// and icon in each pill when not selected
@@ -199,10 +202,10 @@ public extension PillPickerView {
199202
return view
200203
}
201204

202-
/// The height of each pill
203-
func pillHeight(_ value: CGFloat) -> PillPickerView {
205+
/// The minimum height of each pill
206+
func pillMinHeight(_ value: CGFloat) -> PillPickerView {
204207
var view = self
205-
view.options.height = value
208+
view.options.minHeight = value
206209
return view
207210
}
208211

@@ -228,10 +231,17 @@ public extension PillPickerView {
228231
return view
229232
}
230233

231-
/// Padding of content inside each pill
232-
func pillPadding(_ value: CGFloat) -> PillPickerView {
234+
/// Horizontal padding of content inside each pill
235+
func pillPaddingVertical(_ value: CGFloat) -> PillPickerView {
233236
var view = self
234-
view.options.padding = value
237+
view.options.verticalPadding = value
238+
return view
239+
}
240+
241+
/// Horizontal padding of content inside each pill
242+
func pillPaddingHorizontal(_ value: CGFloat) -> PillPickerView {
243+
var view = self
244+
view.options.horizontalPadding = value
235245
return view
236246
}
237247

@@ -328,8 +338,7 @@ struct PillView<T: Pill>: View {
328338
trailingIcon
329339
}
330340
}
331-
.padding(options.padding)
332-
.frame(minWidth: options.minWidth)
341+
.frame(minWidth: options.minWidth, minHeight: options.minHeight)
333342
})
334343
.buttonStyle(
335344
PillItemStyle(
@@ -413,14 +422,13 @@ struct PillItemStyle: ButtonStyle {
413422
let options: PillOptions
414423

415424

416-
417425
func makeBody(configuration: Configuration) -> some View {
418426
configuration.label
419-
.padding(12)
427+
.padding(.horizontal, options.horizontalPadding)
428+
.padding(.vertical, options.verticalPadding)
420429
.background(background)
421430
.foregroundColor(foreground)
422431
.cornerRadius(cornerRadius)
423-
424432
.overlay(
425433
RoundedRectangle(cornerRadius: cornerRadius)
426434
.stroke(borderColor, lineWidth: 1)

0 commit comments

Comments
 (0)