mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-05-19 08:48:16 +00:00
Migrate DisplaySettingsLocalValues
This commit is contained in:
parent
1f73af4822
commit
2ac7f7f342
|
@ -7,44 +7,16 @@ import Observation
|
|||
import Status
|
||||
import SwiftUI
|
||||
|
||||
class DisplaySettingsLocalValues: ObservableObject {
|
||||
@Published var tintColor = Theme.shared.tintColor
|
||||
@Published var primaryBackgroundColor = Theme.shared.primaryBackgroundColor
|
||||
@Published var secondaryBackgroundColor = Theme.shared.secondaryBackgroundColor
|
||||
@Published var labelColor = Theme.shared.labelColor
|
||||
@Published var lineSpacing = Theme.shared.lineSpacing
|
||||
@Published var fontSizeScale = Theme.shared.fontSizeScale
|
||||
@Observable class DisplaySettingsLocalValues {
|
||||
var tintColor = Theme.shared.tintColor
|
||||
var primaryBackgroundColor = Theme.shared.primaryBackgroundColor
|
||||
var secondaryBackgroundColor = Theme.shared.secondaryBackgroundColor
|
||||
var labelColor = Theme.shared.labelColor
|
||||
var lineSpacing = Theme.shared.lineSpacing
|
||||
var fontSizeScale = Theme.shared.fontSizeScale
|
||||
|
||||
private let debouncesDelay: DispatchQueue.SchedulerTimeType.Stride = .seconds(0.5)
|
||||
|
||||
private var subscriptions = Set<AnyCancellable>()
|
||||
|
||||
init() {
|
||||
$tintColor
|
||||
.debounce(for: debouncesDelay, scheduler: DispatchQueue.main)
|
||||
.sink(receiveValue: { newColor in Theme.shared.tintColor = newColor })
|
||||
.store(in: &subscriptions)
|
||||
$primaryBackgroundColor
|
||||
.debounce(for: debouncesDelay, scheduler: DispatchQueue.main)
|
||||
.sink(receiveValue: { newColor in Theme.shared.primaryBackgroundColor = newColor })
|
||||
.store(in: &subscriptions)
|
||||
$secondaryBackgroundColor
|
||||
.debounce(for: debouncesDelay, scheduler: DispatchQueue.main)
|
||||
.sink(receiveValue: { newColor in Theme.shared.secondaryBackgroundColor = newColor })
|
||||
.store(in: &subscriptions)
|
||||
$labelColor
|
||||
.debounce(for: debouncesDelay, scheduler: DispatchQueue.main)
|
||||
.sink(receiveValue: { newColor in Theme.shared.labelColor = newColor })
|
||||
.store(in: &subscriptions)
|
||||
$lineSpacing
|
||||
.debounce(for: debouncesDelay, scheduler: DispatchQueue.main)
|
||||
.sink(receiveValue: { newSpacing in Theme.shared.lineSpacing = newSpacing })
|
||||
.store(in: &subscriptions)
|
||||
$fontSizeScale
|
||||
.debounce(for: debouncesDelay, scheduler: DispatchQueue.main)
|
||||
.sink(receiveValue: { newScale in Theme.shared.fontSizeScale = newScale })
|
||||
.store(in: &subscriptions)
|
||||
}
|
||||
init() { }
|
||||
}
|
||||
|
||||
struct DisplaySettingsView: View {
|
||||
|
@ -54,7 +26,7 @@ struct DisplaySettingsView: View {
|
|||
@EnvironmentObject private var theme: Theme
|
||||
@EnvironmentObject private var userPreferences: UserPreferences
|
||||
|
||||
@StateObject private var localValues = DisplaySettingsLocalValues()
|
||||
@State private var localValues = DisplaySettingsLocalValues()
|
||||
|
||||
@State private var isFontSelectorPresented = false
|
||||
|
||||
|
@ -78,6 +50,30 @@ struct DisplaySettingsView: View {
|
|||
.navigationTitle("settings.display.navigation-title")
|
||||
.scrollContentBackground(.hidden)
|
||||
.background(theme.secondaryBackgroundColor)
|
||||
.task(id: localValues.tintColor) {
|
||||
do { try await Task.sleep(for: .microseconds(500)) } catch { }
|
||||
Theme.shared.tintColor = localValues.tintColor
|
||||
}
|
||||
.task(id: localValues.primaryBackgroundColor) {
|
||||
do { try await Task.sleep(for: .microseconds(500)) } catch { }
|
||||
Theme.shared.primaryBackgroundColor = localValues.primaryBackgroundColor
|
||||
}
|
||||
.task(id: localValues.secondaryBackgroundColor) {
|
||||
do { try await Task.sleep(for: .microseconds(500)) } catch { }
|
||||
Theme.shared.secondaryBackgroundColor = localValues.secondaryBackgroundColor
|
||||
}
|
||||
.task(id: localValues.labelColor) {
|
||||
do { try await Task.sleep(for: .microseconds(500)) } catch { }
|
||||
Theme.shared.labelColor = localValues.labelColor
|
||||
}
|
||||
.task(id: localValues.lineSpacing) {
|
||||
do { try await Task.sleep(for: .microseconds(500)) } catch { }
|
||||
Theme.shared.lineSpacing = localValues.lineSpacing
|
||||
}
|
||||
.task(id: localValues.fontSizeScale) {
|
||||
do { try await Task.sleep(for: .microseconds(500)) } catch { }
|
||||
Theme.shared.fontSizeScale = localValues.fontSizeScale
|
||||
}
|
||||
examplePost
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue