// // ImagePicker.swift // SimpleX // // Created by Evgeny on 23/03/2022. // Copyright © 2022 SimpleX Chat. All rights reserved. // import SwiftUI struct ImagePicker: UIViewControllerRepresentable { @Environment(\.presentationMode) var presentationMode var source: UIImagePickerController.SourceType @Binding var image: UIImage? class Coordinator: NSObject, UINavigationControllerDelegate, UIImagePickerControllerDelegate { let parent: ImagePicker init(_ parent: ImagePicker) { self.parent = parent } func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) { if let uiImage = info[.originalImage] as? UIImage { parent.image = uiImage } parent.presentationMode.wrappedValue.dismiss() } } func makeCoordinator() -> Coordinator { Coordinator(self) } func makeUIViewController(context: UIViewControllerRepresentableContext) -> UIImagePickerController { let picker = UIImagePickerController() picker.sourceType = source picker.allowsEditing = false picker.delegate = context.coordinator return picker } func updateUIViewController(_ uiViewController: UIImagePickerController, context: UIViewControllerRepresentableContext) { } }