Skip to content

Commit 8fe10bf

Browse files
committed
Update SlidersInScrollView demo
1 parent f347475 commit 8fe10bf

File tree

1 file changed

+58
-17
lines changed

1 file changed

+58
-17
lines changed

Demo/Sources/Demo/SlidersInScrollView.swift

Lines changed: 58 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,33 @@ import CompactSlider
33

44
@available(iOS 16.0, macOS 13.0, *)
55
struct SlidersInScrollView: View {
6-
@State private var showEditSheet = false
7-
6+
@State private var showVerticalSheet = false
7+
@State private var showHorizontalSheet = false
8+
89
var body: some View {
9-
Button {
10-
showEditSheet = true
11-
} label: {
12-
Text("Sliders in Sheet in ScrollView")
10+
VStack(spacing: 16) {
11+
Text("Sliders in Sheet")
1312
.font(.title2.bold())
13+
14+
Button {
15+
showVerticalSheet = true
16+
} label: {
17+
Text("Vertical ScrollView")
18+
}
19+
20+
Button {
21+
showHorizontalSheet = true
22+
} label: {
23+
Text("Horizontal ScrollView")
24+
}
1425
}
15-
.sheet(isPresented: $showEditSheet) {
16-
Sheet()
26+
.sheet(isPresented: $showVerticalSheet) {
27+
Sheet(isVertical: true)
28+
.ignoresSafeArea()
29+
.presentationDetents([.fraction(0.3)])
30+
}
31+
.sheet(isPresented: $showHorizontalSheet) {
32+
Sheet(isVertical: false)
1733
.ignoresSafeArea()
1834
.presentationDetents([.fraction(0.3)])
1935
}
@@ -25,23 +41,48 @@ struct SlidersInScrollView: View {
2541
@available(iOS 16.0, macOS 13.0, *)
2642
struct Sheet: View {
2743
@State private var value = 0.5
44+
let isVertical: Bool
2845

2946
var body: some View {
30-
ScrollView {
31-
VStack {
32-
ForEach(0..<20) { index in
47+
Group {
48+
if isVertical {
49+
ScrollView {
50+
VStack {
51+
ForEach(0..<20) { index in
52+
HStack {
53+
Text("\(index < 10 ? "0": "")\(index)")
54+
CustomSlider(value: $value, range: 0...1)
55+
CompactSlider(value: $value)
56+
}
57+
}
58+
.compactSliderOptionsByAdding(.simultaneousGesture)
59+
}
60+
.padding()
61+
.padding(.bottom)
62+
}
63+
} else {
64+
ScrollView(.horizontal) {
3365
HStack {
34-
Text("\(index < 10 ? "0": "")\(index)")
35-
CustomSlider(value: $value, range: 0...1)
36-
CompactSlider(value: $value)
66+
ForEach(0..<20) { index in
67+
VStack(spacing: 16) {
68+
Text("\(index < 10 ? "0": "")\(index)")
69+
CustomSlider(value: $value, range: 0...1)
70+
.frame(height: 40)
71+
CompactSlider(value: $value)
72+
.frame(height: 30)
73+
Spacer()
74+
}
75+
.frame(width: 150)
76+
}
3777
}
78+
.padding()
79+
.padding(.bottom)
80+
.compactSliderOptionsByAdding(.highPriorityGesture)
81+
.frame(maxHeight: .infinity)
3882
}
3983
}
40-
.padding()
41-
.padding(.bottom)
4284
}
4385
.monospacedDigit()
44-
.compactSliderOptionsByAdding(.simultaneousGesture)
4586
}
4687
}
4788

0 commit comments

Comments
 (0)