From ab51d5764870b77f861a59662f0388e3fb8bd465 Mon Sep 17 00:00:00 2001 From: Thomas Ricouard Date: Mon, 3 Apr 2023 13:53:41 +0200 Subject: [PATCH] Cleanup debounce --- .../App/Tabs/Settings/DisplaySettingsView.swift | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/IceCubesApp/App/Tabs/Settings/DisplaySettingsView.swift b/IceCubesApp/App/Tabs/Settings/DisplaySettingsView.swift index 87928fd1..c7e8be8f 100644 --- a/IceCubesApp/App/Tabs/Settings/DisplaySettingsView.swift +++ b/IceCubesApp/App/Tabs/Settings/DisplaySettingsView.swift @@ -13,32 +13,34 @@ class DisplaySettingsLocalValues: ObservableObject { @Published var labelColor = Theme.shared.labelColor @Published var lineSpacing = Theme.shared.lineSpacing @Published var fontSizeScale = Theme.shared.fontSizeScale + + private let debouncesDelay: DispatchQueue.SchedulerTimeType.Stride = .seconds(0.5) private var subscriptions = Set() init() { $tintColor - .debounce(for: .seconds(0.5), scheduler: DispatchQueue.main) + .debounce(for: debouncesDelay, scheduler: DispatchQueue.main) .sink(receiveValue: { newColor in Theme.shared.tintColor = newColor }) .store(in: &subscriptions) $primaryBackgroundColor - .debounce(for: .seconds(0.5), scheduler: DispatchQueue.main) + .debounce(for: debouncesDelay, scheduler: DispatchQueue.main) .sink(receiveValue: { newColor in Theme.shared.primaryBackgroundColor = newColor }) .store(in: &subscriptions) $secondaryBackgroundColor - .debounce(for: .seconds(0.5), scheduler: DispatchQueue.main) + .debounce(for: debouncesDelay, scheduler: DispatchQueue.main) .sink(receiveValue: { newColor in Theme.shared.secondaryBackgroundColor = newColor }) .store(in: &subscriptions) $labelColor - .debounce(for: .seconds(0.5), scheduler: DispatchQueue.main) + .debounce(for: debouncesDelay, scheduler: DispatchQueue.main) .sink(receiveValue: { newColor in Theme.shared.labelColor = newColor }) .store(in: &subscriptions) $lineSpacing - .debounce(for: .seconds(0.5), scheduler: DispatchQueue.main) + .debounce(for: debouncesDelay, scheduler: DispatchQueue.main) .sink(receiveValue: { newSpacing in Theme.shared.lineSpacing = newSpacing }) .store(in: &subscriptions) $fontSizeScale - .debounce(for: .seconds(0.5), scheduler: DispatchQueue.main) + .debounce(for: debouncesDelay, scheduler: DispatchQueue.main) .sink(receiveValue: { newScale in Theme.shared.fontSizeScale = newScale }) .store(in: &subscriptions) }