The ColorPicker sheet should dismiss when the user presses the eyedropper so that they can pick a color from the screen behind it. I made my own coordinator, so is there anyone to specifically code for when the eyedropper is pressed? Currently my sheet only dismisses half a second after a color is selected.
import Foundation
import SwiftUI
struct ColorPicker: UIViewControllerRepresentable {
@Environment(\.presentationMode) var presentationMode
@Binding var colors: UIColor
func makeCoordinator() -> Coordinator {
Coordinator(color1: self)
}
func makeUIViewController(context: Context) -> UIColorPickerViewController {
let colorPicker = UIColorPickerViewController()
colorPicker.delegate = context.coordinator
colorPicker.selectedColor = colors
return colorPicker
}
func updateUIViewController(_ uiViewController: UIColorPickerViewController, context: UIViewControllerRepresentableContext<ColorPicker>) {
uiViewController.selectedColor.resolvedColor(with: UITraitCollection.current)
}
class Coordinator: NSObject, UINavigationControllerDelegate, UIColorPickerViewControllerDelegate {
var colorPick: ColorPicker
init(color1: ColorPicker){
colorPick = color1
}
func colorPickerViewControllerDidSelectColor(_ viewController: UIColorPickerViewController) {
self.colorPick.colors = viewController.selectedColor
do{
usleep(500000)
viewController.dismiss(animated: true, completion: nil)
}
}
func colorPickerViewControllerDidFinish(_ viewController: UIColorPickerViewController) {
}
}
}