Skip to content

Commit b103876

Browse files
committed
Update SettingsView in WaterfallGridSample
1 parent ac68f5a commit b103876

File tree

2 files changed

+52
-52
lines changed

2 files changed

+52
-52
lines changed

WaterfallGridSample/WaterfallGridSample/Settings/Settings.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ struct Settings {
1818
var animationSpeed: Double
1919

2020
var columns: Double {
21-
#if os(OSX) || os(tvOS) || targetEnvironment(macCatalyst)
21+
#if os(OSX) || os(tvOS) || targetEnvironment(macCatalyst) || os(visionOS)
2222
return columnsInLandscape
2323
#else
2424
return columnsInPortrait

WaterfallGridSample/WaterfallGridSample/Settings/SettingsView.swift

+51-51
Original file line numberDiff line numberDiff line change
@@ -24,76 +24,76 @@ struct SettingsView: View {
2424
}
2525

2626
var body: some View {
27-
GeometryReader { geometry in
28-
NavigationView {
29-
Form() {
30-
Section(header: Text("Columns")) {
31-
#if os(iOS) && !targetEnvironment(macCatalyst)
32-
self.valueSelector(self.$newSettings.columnsInPortrait, bounds: 1...10, step: 1, label: "Portrait", in: geometry)
33-
self.valueSelector(self.$newSettings.columnsInLandscape, bounds: 1...10, step: 1, label: "Landscape", in: geometry)
34-
#else
35-
self.valueSelector(self.$newSettings.columnsInLandscape, bounds: 1...10, step: 1, label: "Columns", in: geometry)
36-
#endif
37-
}
27+
NavigationView {
28+
Form() {
29+
Section(header: Text("Columns")) {
30+
#if os(iOS) && !targetEnvironment(macCatalyst)
31+
self.valueSelector(self.$newSettings.columnsInPortrait, bounds: 1...10, step: 1, label: "Portrait")
32+
self.valueSelector(self.$newSettings.columnsInLandscape, bounds: 1...10, step: 1, label: "Landscape")
33+
#else
34+
self.valueSelector(self.$newSettings.columnsInLandscape, bounds: 1...10, step: 1, label: "Columns")
35+
#endif
36+
}
3837

39-
Section(header: Text("Spacing")) {
40-
self.valueSelector(self.$newSettings.spacing, bounds: 0...40, step: 1, label: "Spacing", in: geometry)
41-
}
38+
Section(header: Text("Spacing")) {
39+
self.valueSelector(self.$newSettings.spacing, bounds: 0...40, step: 1, label: "Spacing")
40+
}
4241

43-
Section(header: Text("Padding")) {
44-
self.valueSelector(self.$newSettings.padding.top, bounds: 0...40, step: 1, label: "Top", in: geometry)
45-
self.valueSelector(self.$newSettings.padding.leading, bounds: 0...40, step: 1, label: "Leading", in: geometry)
46-
self.valueSelector(self.$newSettings.padding.bottom, bounds: 0...40, step: 1, label: "Bottom", in: geometry)
47-
self.valueSelector(self.$newSettings.padding.trailing, bounds: 0...40, step: 1, label: "Trailing", in: geometry)
48-
}
42+
Section(header: Text("Padding")) {
43+
self.valueSelector(self.$newSettings.padding.top, bounds: 0...40, step: 1, label: "Top")
44+
self.valueSelector(self.$newSettings.padding.leading, bounds: 0...40, step: 1, label: "Leading")
45+
self.valueSelector(self.$newSettings.padding.bottom, bounds: 0...40, step: 1, label: "Bottom")
46+
self.valueSelector(self.$newSettings.padding.trailing, bounds: 0...40, step: 1, label: "Trailing")
47+
}
4948

50-
Section(header: Text("Scroll Options")) {
51-
Picker(selection: self.$newSettings.scrollDirection, label: Text("Direction")) {
52-
ForEach(Axis.allCases, id: \.self) { axes in
53-
Text(axes.description.capitalized)
54-
}
49+
Section(header: Text("Scroll Options")) {
50+
Picker(selection: self.$newSettings.scrollDirection, label: Text("Direction")) {
51+
ForEach(Axis.allCases, id: \.self) { axes in
52+
Text(axes.description.capitalized)
5553
}
56-
Toggle(isOn: self.$newSettings.showsIndicators) {
57-
Text("Show Indicators")
58-
}
59-
.pickerStyle(SegmentedPickerStyle())
6054
}
61-
62-
Section(header: Text("Animation")) {
63-
Toggle(isOn: self.$animationEnabled) {
64-
Text("Enabled")
65-
}
66-
if self.animationEnabled {
67-
self.valueSelector(self.$newSettings.animationSpeed, bounds: 0.1...1, step: 0.05, label: "Speed", in: geometry)
68-
}
55+
Toggle(isOn: self.$newSettings.showsIndicators) {
56+
Text("Show Indicators")
6957
}
58+
.pickerStyle(SegmentedPickerStyle())
7059
}
71-
.onDisappear {
72-
let animation = Animation.default.speed(self.newSettings.animationSpeed)
73-
self.newSettings.animation = self.animationEnabled ? animation : nil
74-
self.settings.wrappedValue = self.newSettings
60+
61+
Section(header: Text("Animation")) {
62+
Toggle(isOn: self.$animationEnabled) {
63+
Text("Enabled")
64+
}
65+
if self.animationEnabled {
66+
self.valueSelector(self.$newSettings.animationSpeed, bounds: 0.1...1, step: 0.05, label: "Speed")
67+
}
7568
}
76-
.customNavigationBarTitle(Text("Settings"), displayMode: .inline)
77-
.customNavigationBarItems(leading: self.leadingNavigationBarItems(), trailing: self.trailingNavigationBarItems())
7869
}
70+
.onDisappear {
71+
let animation = Animation.default.speed(self.newSettings.animationSpeed)
72+
self.newSettings.animation = self.animationEnabled ? animation : nil
73+
self.settings.wrappedValue = self.newSettings
74+
}
75+
.customNavigationBarTitle(Text("Settings"), displayMode: .inline)
76+
.customNavigationBarItems(leading: self.leadingNavigationBarItems(), trailing: self.trailingNavigationBarItems())
7977
}
8078
.navigationViewStyle(StackNavigationViewStyle())
8179
}
8280

83-
private func valueSelector<V>(_ selection: Binding<V>, bounds: ClosedRange<V>, step: V.Stride, label: String, in geometry: GeometryProxy) -> some View
81+
private func valueSelector<V>(_ selection: Binding<V>, bounds: ClosedRange<V>, step: V.Stride, label: String) -> some View
8482
where V : BinaryFloatingPoint, V.Stride : BinaryFloatingPoint {
85-
#if os(tvOS)
86-
return Picker(selection: selection, label: Text(label)) {
83+
#if os(tvOS) || os(visionOS)
84+
Picker(selection: selection, label: Text(label)) {
8785
ForEach(Array(stride(from: bounds.lowerBound, through: bounds.upperBound, by: step)), id: \.self) { index in
8886
Text(String(format:"%.2f", Double(index)))
8987
}
9088
}
9189
#else
92-
return HStack() {
93-
Text("\(label): \(String(format:"%.2f", Double(selection.wrappedValue)))")
94-
Spacer()
95-
Slider(value: selection, in: bounds, step: step)
96-
.frame(width: geometry.size.width / 2)
90+
GeometryReader { geometry in
91+
HStack() {
92+
Text("\(label): \(String(format:"%.2f", Double(selection.wrappedValue)))")
93+
Spacer()
94+
Slider(value: selection, in: bounds, step: step)
95+
.frame(width: geometry.size.width / 2)
96+
}
9797
}
9898
#endif
9999
}

0 commit comments

Comments
 (0)