Post

Replies

Boosts

Views

Activity

Reply to SwiftUI ColorPicker does not dismiss upon eyedropper button press
I've encountered the same problem, and use UIColorWell as a work around. struct ColorPickerWellView: UIViewRepresentable { 		private var selectedColor: Color 		let onColorPicked: (UIColor) -> Void 		init(selectedColor: Color, onColorPicked: @escaping (UIColor) -> Void) { 				self.selectedColor = selectedColor 				self.onColorPicked = onColorPicked 		} 		func makeUIView(context: Context) -> UIView { 				let colorWell = UIColorWell(frame: CGRect(x: 0, y: 0, width: 100, height: 50)) 				colorWell.title = "Select Color" 				colorWell.selectedColor = UIColor(selectedColor) 				colorWell.addTarget(context.coordinator, action: #selector(context.coordinator.colorWellChanged), for: .valueChanged) 				return colorWell 		} 		func updateUIView(_: UIView, context _: Context) {} 		func makeCoordinator() -> Coordinator { 				Coordinator( 						onColorPicked: self.onColorPicked 				) 		} 		class Coordinator: NSObject { 				private let onColorPicked: (UIColor) -> Void 				init(onColorPicked: @escaping (UIColor) -> Void) { 						self.onColorPicked = onColorPicked 				} 				@objc func colorWellChanged(_ sender: UIColorWell) { 						if let c = sender.selectedColor { 								self.onColorPicked(c) 						} 				} 		} }
Dec ’20
Reply to SwiftUI ColorPicker does not dismiss upon eyedropper button press
struct ColorPickerWellView: UIViewRepresentable { 		let selectedColor: UInt32 		let onColorPicked: (UIColor) -> Void 		init(selectedColor: UInt32, onColorPicked: @escaping (UIColor) -> Void) { 				self.selectedColor = selectedColor 				self.onColorPicked = onColorPicked 		} 		func makeUIView(context: Context) -> UIColorWell { 				let colorWell = UIColorWell(frame: CGRect(x: 0, y: 0, width: 50, height: 50)) 				colorWell.title = "Select Color" 				colorWell.selectedColor = UIColor(selectedColor.toColor()) 				colorWell.supportsAlpha = true 				colorWell.addTarget(context.coordinator, action: #selector(context.coordinator.colorWellChanged), for: .valueChanged) 				return colorWell 		} 		func updateUIView(_ colorWell: UIColorWell, context _: Context) { 				colorWell.selectedColor = UIColor(selectedColor.toColor()) 		} 		func makeCoordinator() -> Coordinator { 				Coordinator( 						onColorPicked: self.onColorPicked 				) 		} 		class Coordinator: NSObject { 				private let onColorPicked: (UIColor) -> Void 				init(onColorPicked: @escaping (UIColor) -> Void) { 						self.onColorPicked = onColorPicked 				} 				@objc func colorWellChanged(_ sender: UIColorWell) { 						if let c = sender.selectedColor { 								print(c) 								self.onColorPicked(c) 						} 				} 		} } updated
Dec ’20