diff --git a/ConversationsClassic/AppData/Store/ConversationStore.swift b/ConversationsClassic/AppData/Store/ConversationStore.swift index 63ec66b..f2fd796 100644 --- a/ConversationsClassic/AppData/Store/ConversationStore.swift +++ b/ConversationsClassic/AppData/Store/ConversationStore.swift @@ -64,6 +64,10 @@ extension ConversationStore { // await client.uploadMedia(item.url) // } } + + func sendCaptured(_ data: Data, _ type: GalleryMediaType) async { + print("captured!", data, type) + } } private extension ConversationStore { diff --git a/ConversationsClassic/View/Main/Conversation/Attachments/MediaPicker/CameraCellPreview.swift b/ConversationsClassic/View/Main/Conversation/Attachments/MediaPicker/CameraCellPreview.swift index 1a0da8e..ec720b9 100644 --- a/ConversationsClassic/View/Main/Conversation/Attachments/MediaPicker/CameraCellPreview.swift +++ b/ConversationsClassic/View/Main/Conversation/Attachments/MediaPicker/CameraCellPreview.swift @@ -3,6 +3,7 @@ import SwiftUI struct CameraCellPreview: View { @Environment(\.router) var router + @EnvironmentObject var conversation: ConversationStore @EnvironmentObject var store: AttachmentsStore var body: some View { @@ -24,8 +25,13 @@ struct CameraCellPreview: View { } .onTapGesture { router.showScreen(.fullScreenCover) { _ in - CameraPicker() - .ignoresSafeArea(.all) + CameraPicker { data, type in + Task { + await conversation.sendCaptured(data, type) + } + router.dismissEnvironment() + } + .ignoresSafeArea(.all) } } } else { diff --git a/ConversationsClassic/View/Main/Conversation/Attachments/MediaPicker/CameraPicker.swift b/ConversationsClassic/View/Main/Conversation/Attachments/MediaPicker/CameraPicker.swift index 646a0d4..b97ee54 100644 --- a/ConversationsClassic/View/Main/Conversation/Attachments/MediaPicker/CameraPicker.swift +++ b/ConversationsClassic/View/Main/Conversation/Attachments/MediaPicker/CameraPicker.swift @@ -3,8 +3,7 @@ import Photos import SwiftUI struct CameraPicker: UIViewControllerRepresentable { - // var sourceType: UIImagePickerController.SourceType - // var completionHandler: (Data, SharingCameraMediaType) -> Void + var completionHandler: (Data, GalleryMediaType) -> Void func makeUIViewController(context: Context) -> UIImagePickerController { let picker = UIImagePickerController() @@ -34,17 +33,17 @@ struct CameraPicker: UIViewControllerRepresentable { // swiftlint:disable:next force_cast let mediaType = info[.mediaType] as! String - // if mediaType == UTType.image.identifier { - // if let image = info[.originalImage] as? UIImage { - // let data = image.jpegData(compressionQuality: 1.0) ?? Data() - // parent.completionHandler(data, .photo) - // } - // } else if mediaType == UTType.movie.identifier { - // if let url = info[.mediaURL] as? URL { - // let data = try? Data(contentsOf: url) - // parent.completionHandler(data ?? Data(), .video) - // } - // } + if mediaType == UTType.image.identifier { + if let image = info[.originalImage] as? UIImage { + let data = image.jpegData(compressionQuality: 1.0) ?? Data() + parent.completionHandler(data, .photo) + } + } else if mediaType == UTType.movie.identifier { + if let url = info[.mediaURL] as? URL { + let data = try? Data(contentsOf: url) + parent.completionHandler(data ?? Data(), .video) + } + } } } }