Skip to content

Commit

Permalink
sample: add more SwiftUI examples
Browse files Browse the repository at this point in the history
  • Loading branch information
twittemb committed Oct 1, 2022
1 parent 858fa4f commit 8ae6142
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions Sample/Sample/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ struct ContentView: View {
@State var throttledCounter = 0
@State var debouncedCounter = 0
@State var text = ""
@StateObject var bindingRegulator = Throttler<String>(dueTime: .seconds(1))
@State var isOn = false
@State var steps = 0
@StateObject var textRegulator = Throttler<String>(dueTime: .seconds(1))
@StateObject var toggleRegulator = Debouncer<Bool>(dueTime: .seconds(1))
@StateObject var stepperRegulator = Debouncer<Int>(dueTime: .seconds(1))

var body: some View {
VStack {
Expand Down Expand Up @@ -50,14 +54,32 @@ struct ContentView: View {
TextField(
text: self
.$text
.perform(regulator: bindingRegulator) { text in
.perform(regulator: textRegulator) { text in
print("regulated text \(text)")
}
) {
Text("prompt")
}
.textFieldStyle(RoundedBorderTextFieldStyle())

Toggle(
isOn: self
.$isOn
.perform(regulator: toggleRegulator) { value in
print("regulated toggle \(value)")
}
) {
Text("Regulated toogle")
}

Stepper(
"Regulated stepper \(self.steps)",
value: self
.$steps
.perform(regulator: stepperRegulator) { value in
print("regulated stepper \(value)")
}
)
}
.padding()
}
Expand Down

0 comments on commit 8ae6142

Please sign in to comment.