Skip to content

Commit 6de466d

Browse files
committed
Add convenience methods
1 parent c694f21 commit 6de466d

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

Example/SettingExample/PreferencesView.swift

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,11 @@ struct PreferencesView: View {
158158
"Every Day",
159159
"Every Week"
160160
],
161-
selectedIndex: $model.notificationIndex,
162-
choicesConfiguration: .init(pickerDisplayMode: .navigation)
161+
selectedIndex: $model.notificationIndex
163162
)
163+
.pickerDisplayMode(.navigation)
164164
}
165-
165+
166166
SettingGroup {
167167
SettingPicker(
168168
title: "Frequency (Menu)",
@@ -171,11 +171,11 @@ struct PreferencesView: View {
171171
"Every Day",
172172
"Every Week"
173173
],
174-
selectedIndex: $model.notificationIndex,
175-
choicesConfiguration: .init(pickerDisplayMode: .menu)
174+
selectedIndex: $model.notificationIndex
176175
)
176+
.pickerDisplayMode(.menu)
177177
}
178-
178+
179179
SettingGroup(header: "Frequency (Inline)") {
180180
SettingPicker(
181181
title: "Frequency (Inline)",
@@ -184,9 +184,9 @@ struct PreferencesView: View {
184184
"Every Day",
185185
"Every Week"
186186
],
187-
selectedIndex: $model.notificationIndex,
188-
choicesConfiguration: .init(pickerDisplayMode: .inline)
187+
selectedIndex: $model.notificationIndex
189188
)
189+
.pickerDisplayMode(.inline)
190190
}
191191

192192
SettingGroup(header: "You can't turn these off. HEHEHAHA!") {
@@ -257,7 +257,7 @@ struct PreferencesView: View {
257257
selectedIndex: $model.modeIndex
258258
)
259259
}
260-
260+
261261
SettingGroup {
262262
SettingTextField(placeholder: "Enter text here", text: $model.text)
263263
}
@@ -313,4 +313,3 @@ struct PreferencesView: View {
313313
}
314314
}
315315
}
316-

Sources/Views/SettingPicker.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,15 @@ public struct SettingPicker: View, Setting {
103103
}
104104
}
105105

106+
/// Convenience modifiers.
107+
public extension SettingPicker {
108+
func pickerDisplayMode(_ pickerDisplayMode: PickerDisplayMode) -> SettingPicker {
109+
var picker = self
110+
picker.choicesConfiguration.pickerDisplayMode = pickerDisplayMode
111+
return picker
112+
}
113+
}
114+
106115
struct SettingPickerView: View {
107116
let title: String
108117
var choices: [String]

0 commit comments

Comments
 (0)