Skip to content

Commit 51d3f04

Browse files
committed
Add interaction playground
1 parent 6f0beba commit 51d3f04

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#if canImport(AndroidSwiftUI)
2+
import AndroidSwiftUI
3+
#else
4+
import SwiftUI
5+
#endif
6+
7+
struct InteractionPlayground: View {
8+
@State private var taps = 0
9+
@State private var appearances = 0
10+
@State private var slider = 0.0
11+
@State private var sliderChanges = 0
12+
@State private var blocked = true
13+
var body: some View {
14+
ScrollView {
15+
VStack(alignment: .leading, spacing: 0) {
16+
Example("onTapGesture") {
17+
VStack(alignment: .leading, spacing: 8) {
18+
Text("Tapped \(taps) time(s)")
19+
Text("Tap this row")
20+
.foregroundColor(.white)
21+
.padding()
22+
.background(Color.blue)
23+
.cornerRadius(8)
24+
.onTapGesture { taps += 1 }
25+
}
26+
}
27+
Example("onAppear") {
28+
Text("This row appeared \(appearances) time(s)")
29+
.onAppear { appearances += 1 }
30+
}
31+
Example("onChange") {
32+
VStack(alignment: .leading, spacing: 8) {
33+
Slider(value: $slider, in: 0...1)
34+
Text("Slider changed \(sliderChanges) time(s)")
35+
}
36+
.onChange(of: slider) { sliderChanges += 1 }
37+
}
38+
Example("disabled") {
39+
VStack(alignment: .leading, spacing: 8) {
40+
Button(blocked ? "Disabled button" : "Enabled button") { taps += 1 }
41+
.disabled(blocked)
42+
Button("Toggle disabled") { blocked.toggle() }
43+
}
44+
}
45+
}
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)