Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve text field input #27

Closed
wants to merge 9 commits into from
46 changes: 46 additions & 0 deletions Color Picker/AppState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import Sentry

@MainActor
final class AppState: ObservableObject {
// MARK: - Properties

static let shared = AppState()

var cancellables = Set<AnyCancellable>()
Expand Down Expand Up @@ -128,6 +130,14 @@ final class AppState: ObservableObject {
}
}

@Published var hexColor = ""
@Published var hslColor = ""
@Published var rgbColor = ""
@Published var lchColor = ""
@Published var isPreventingUpdate = false
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these moved to AppState? AppState is for state that is required globally. This state is only needed for picker screen. I think you can just pass updateColorsFromPanel to the ColorPickerScreen view.


// MARK: - Methods

init() {
setUpConfig()

Expand Down Expand Up @@ -224,4 +234,40 @@ final class AppState: ObservableObject {
func handleAppReopen() {
handleMenuBarIcon()
}

// TODO: Find a better way to handle this.
func updateColorsFromPanel(
excludeHex: Bool = false,
excludeHSL: Bool = false,
excludeRGB: Bool = false,
excludeLCH: Bool = false,
preventUpdate: Bool = false,
color: NSColor
) {
if preventUpdate {
isPreventingUpdate = true
}

if !excludeHex {
hexColor = color.hexColorString
}

if !excludeHSL {
hslColor = color.hslColorString
}

if !excludeRGB {
rgbColor = color.rgbColorString
}

if !excludeLCH {
lchColor = color.lchColorString
}

if preventUpdate {
DispatchQueue.main.async {
self.isPreventingUpdate = false
}
}
}
}
Loading