From 8ae614256cde0e7c4c87d60ad1403f5a3018e663 Mon Sep 17 00:00:00 2001 From: Thibault Wittemberg Date: Sat, 1 Oct 2022 11:50:56 +0200 Subject: [PATCH] sample: add more SwiftUI examples --- Sample/Sample/ContentView.swift | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/Sample/Sample/ContentView.swift b/Sample/Sample/ContentView.swift index 8737483..e7952ae 100644 --- a/Sample/Sample/ContentView.swift +++ b/Sample/Sample/ContentView.swift @@ -12,7 +12,11 @@ struct ContentView: View { @State var throttledCounter = 0 @State var debouncedCounter = 0 @State var text = "" - @StateObject var bindingRegulator = Throttler(dueTime: .seconds(1)) + @State var isOn = false + @State var steps = 0 + @StateObject var textRegulator = Throttler(dueTime: .seconds(1)) + @StateObject var toggleRegulator = Debouncer(dueTime: .seconds(1)) + @StateObject var stepperRegulator = Debouncer(dueTime: .seconds(1)) var body: some View { VStack { @@ -50,7 +54,7 @@ struct ContentView: View { TextField( text: self .$text - .perform(regulator: bindingRegulator) { text in + .perform(regulator: textRegulator) { text in print("regulated text \(text)") } ) { @@ -58,6 +62,24 @@ struct ContentView: View { } .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() }