Skip to content

Commit 8ae6142

Browse files
committed
sample: add more SwiftUI examples
1 parent 858fa4f commit 8ae6142

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

Sample/Sample/ContentView.swift

+24-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ struct ContentView: View {
1212
@State var throttledCounter = 0
1313
@State var debouncedCounter = 0
1414
@State var text = ""
15-
@StateObject var bindingRegulator = Throttler<String>(dueTime: .seconds(1))
15+
@State var isOn = false
16+
@State var steps = 0
17+
@StateObject var textRegulator = Throttler<String>(dueTime: .seconds(1))
18+
@StateObject var toggleRegulator = Debouncer<Bool>(dueTime: .seconds(1))
19+
@StateObject var stepperRegulator = Debouncer<Int>(dueTime: .seconds(1))
1620

1721
var body: some View {
1822
VStack {
@@ -50,14 +54,32 @@ struct ContentView: View {
5054
TextField(
5155
text: self
5256
.$text
53-
.perform(regulator: bindingRegulator) { text in
57+
.perform(regulator: textRegulator) { text in
5458
print("regulated text \(text)")
5559
}
5660
) {
5761
Text("prompt")
5862
}
5963
.textFieldStyle(RoundedBorderTextFieldStyle())
6064

65+
Toggle(
66+
isOn: self
67+
.$isOn
68+
.perform(regulator: toggleRegulator) { value in
69+
print("regulated toggle \(value)")
70+
}
71+
) {
72+
Text("Regulated toogle")
73+
}
74+
75+
Stepper(
76+
"Regulated stepper \(self.steps)",
77+
value: self
78+
.$steps
79+
.perform(regulator: stepperRegulator) { value in
80+
print("regulated stepper \(value)")
81+
}
82+
)
6183
}
6284
.padding()
6385
}

0 commit comments

Comments
 (0)