UIColorPickerViewController works incorrect in ios 17

UIColorPickerViewController opens, but does not work and appears incorrect

// swiftui

@State private var showDialog = false
@State private var color: Color = .white
// some code swiftui
Button("Title") {
    showDialog = true
}
.sheet(isPresented: $showDialog) {
    ColorPickerViewRepresentable(color: $color)
}

// uikit
struct ColorPickerViewRepresentable: UIViewControllerRepresentable {

    @Binding var color: Color

    func makeUIViewController(context: Context) -> UIColorPickerViewController {
        let vc = UIColorPickerViewController()
        vc.delegate = context.coordinator
        vc.selectedColor = UIColor(color)
        vc.supportsAlpha = false
        return vc
    }

    func updateUIViewController(_ uiViewController: UIColorPickerViewController, context: Context) {
        uiViewController.selectedColor.resolvedColor(with: UITraitCollection.current)
    }

    func makeCoordinator() -> Coordinator {
        return Coordinator(parent: self)
    }

    class Coordinator: NSObject, UIColorPickerViewControllerDelegate {
        var parent: ColorPickerViewRepresentable

        init(parent: ColorPickerViewRepresentable) {
            self.parent = parent
        }
        
        func colorPickerViewControllerDidFinish(_ viewController: UIColorPickerViewController) {
            parent.color = Color(uiColor: viewController.selectedColor)
        }
    }
}

It's not working because parent.color in Coordinator is not returned to UIColorPickerViewController. Use a Binding variable in Coordinator to pass the selected color back to UIColorPickerViewController. Besides, why do you use UIColorPickerViewController to access UIColorPickerViewController? SwiftUI has a guy named ColorPicker.

Thank you for reply. It works for iOS 15-16.

I need a custom view of ColorPicker. So ColorPicker by SwiftUI is not best solution.

UIColorPickerViewController works incorrect in ios 17
 
 
Q