Skip to content

Commit cb8f060

Browse files
committed
Add convenience methods
1 parent 3dd3008 commit cb8f060

2 files changed

Lines changed: 27 additions & 6 deletions

File tree

Example/SettingExample/PlaygroundSettingView.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,25 @@
99
import Setting
1010
import SwiftUI
1111

12-
class PlaygroundSettingViewModel: ObservableObject {}
13-
1412
struct PlaygroundSettingView: View {
1513
var body: some View {
1614
SettingStack {
1715
SettingPage(title: "Settings") {
1816
SettingGroup {
1917
SettingPage(title: "Subsettings") {
20-
SettingGroup {
21-
22-
}
18+
SettingGroup {}
2319
}
20+
.previewIcon("star.fill")
2421
}
2522
}
2623
}
2724
}
2825
}
26+
2927
struct PlaygroundSettingView_Previews: PreviewProvider {
3028
static var previews: some View {
3129
PlaygroundSettingView()
3230
}
3331
}
32+
33+
class PlaygroundSettingViewModel: ObservableObject {}

Sources/Item/SettingPage.swift

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,31 @@ public struct SettingPage: SettingItem {
7070
}
7171
}
7272

73+
/// Convenience modifiers.
74+
public extension SettingPage {
75+
func previewIcon(_ icon: String, backgroundColor: Color = .blue) -> SettingPage {
76+
var page = self
77+
page.previewConfiguration.icon = .system(icon: icon, backgroundColor: backgroundColor)
78+
return page
79+
}
80+
81+
func previewIcon(icon: SettingIcon) -> SettingPage {
82+
var page = self
83+
page.previewConfiguration.icon = icon
84+
return page
85+
}
86+
87+
func previewIndicator(_ indicator: String) -> SettingPage {
88+
var page = self
89+
page.previewConfiguration.indicator = indicator
90+
return page
91+
}
92+
}
93+
7394
struct SettingPageView<Content>: View where Content: View {
7495
var title: String
7596
var spacing = CGFloat(20)
76-
var verticalPadding = CGFloat(6)
97+
var verticalPadding = CGFloat(12)
7798
var backgroundColor = Setting.secondaryBackgroundColor
7899
var navigationTitleDisplayMode = SettingPage.NavigationTitleDisplayMode.inline
79100
var isInitialPage = false

0 commit comments

Comments
 (0)