From 6c0450ac9ddb0bdf1baa7174ae03d73a46abc3d4 Mon Sep 17 00:00:00 2001 From: Borut Tomazin Date: Tue, 12 Nov 2024 09:02:14 +0100 Subject: [PATCH] Address PR comment. --- .../SimpleColorPicker/SimpleColorPicker.swift | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Sources/UI/SwiftUI/Views/SimpleColorPicker/SimpleColorPicker.swift b/Sources/UI/SwiftUI/Views/SimpleColorPicker/SimpleColorPicker.swift index 1e37bed8..a6d080ef 100644 --- a/Sources/UI/SwiftUI/Views/SimpleColorPicker/SimpleColorPicker.swift +++ b/Sources/UI/SwiftUI/Views/SimpleColorPicker/SimpleColorPicker.swift @@ -11,11 +11,16 @@ import SwiftUI import Combine /// SwiftUI wrapper for NSColorWell, allowing the selection of colors with a customizable size. -struct SimpleColorPicker: NSViewRepresentable { +public struct SimpleColorPicker: NSViewRepresentable { @Binding var selection: Color var size: CGSize? - func makeNSView(context: Context) -> NSColorWell { + public init(selection: Binding, size: CGSize? = nil) { + self._selection = selection + self.size = size + } + + public func makeNSView(context: Context) -> NSColorWell { let colorWell: NSColorWell if #available(macOS 13.0, *) { colorWell = NSColorWell(style: .minimal) @@ -38,7 +43,7 @@ struct SimpleColorPicker: NSViewRepresentable { return colorWell } - func updateNSView(_ nsView: NSColorWell, context: Context) { + public func updateNSView(_ nsView: NSColorWell, context: Context) { context.coordinator.colorDidChange = { selection = Color(nsColor: $0) } @@ -54,12 +59,12 @@ struct SimpleColorPicker: NSViewRepresentable { } } - func makeCoordinator() -> Coordinator { + public func makeCoordinator() -> Coordinator { Coordinator() } @MainActor - class Coordinator: NSObject { + public class Coordinator: NSObject { var colorDidChange: ((NSColor) -> Void)? private var cancellable: AnyCancellable?