mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-06-10 09:19:22 +00:00
Migrate DisplaySettingsLocalValues
This commit is contained in:
parent
1f73af4822
commit
2ac7f7f342
|
@ -7,44 +7,16 @@ import Observation
|
||||||
import Status
|
import Status
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
class DisplaySettingsLocalValues: ObservableObject {
|
@Observable class DisplaySettingsLocalValues {
|
||||||
@Published var tintColor = Theme.shared.tintColor
|
var tintColor = Theme.shared.tintColor
|
||||||
@Published var primaryBackgroundColor = Theme.shared.primaryBackgroundColor
|
var primaryBackgroundColor = Theme.shared.primaryBackgroundColor
|
||||||
@Published var secondaryBackgroundColor = Theme.shared.secondaryBackgroundColor
|
var secondaryBackgroundColor = Theme.shared.secondaryBackgroundColor
|
||||||
@Published var labelColor = Theme.shared.labelColor
|
var labelColor = Theme.shared.labelColor
|
||||||
@Published var lineSpacing = Theme.shared.lineSpacing
|
var lineSpacing = Theme.shared.lineSpacing
|
||||||
@Published var fontSizeScale = Theme.shared.fontSizeScale
|
var fontSizeScale = Theme.shared.fontSizeScale
|
||||||
|
|
||||||
private let debouncesDelay: DispatchQueue.SchedulerTimeType.Stride = .seconds(0.5)
|
|
||||||
|
|
||||||
private var subscriptions = Set<AnyCancellable>()
|
init() { }
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct DisplaySettingsView: View {
|
struct DisplaySettingsView: View {
|
||||||
|
@ -54,7 +26,7 @@ struct DisplaySettingsView: View {
|
||||||
@EnvironmentObject private var theme: Theme
|
@EnvironmentObject private var theme: Theme
|
||||||
@EnvironmentObject private var userPreferences: UserPreferences
|
@EnvironmentObject private var userPreferences: UserPreferences
|
||||||
|
|
||||||
@StateObject private var localValues = DisplaySettingsLocalValues()
|
@State private var localValues = DisplaySettingsLocalValues()
|
||||||
|
|
||||||
@State private var isFontSelectorPresented = false
|
@State private var isFontSelectorPresented = false
|
||||||
|
|
||||||
|
@ -78,6 +50,30 @@ struct DisplaySettingsView: View {
|
||||||
.navigationTitle("settings.display.navigation-title")
|
.navigationTitle("settings.display.navigation-title")
|
||||||
.scrollContentBackground(.hidden)
|
.scrollContentBackground(.hidden)
|
||||||
.background(theme.secondaryBackgroundColor)
|
.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
|
examplePost
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue