This commit is contained in:
fmodf 2024-08-17 18:25:35 +02:00
parent a52b2d99b6
commit a3a57f8b2f
3 changed files with 24 additions and 15 deletions

View file

@ -64,6 +64,10 @@ extension ConversationStore {
// await client.uploadMedia(item.url) // await client.uploadMedia(item.url)
// } // }
} }
func sendCaptured(_ data: Data, _ type: GalleryMediaType) async {
print("captured!", data, type)
}
} }
private extension ConversationStore { private extension ConversationStore {

View file

@ -3,6 +3,7 @@ import SwiftUI
struct CameraCellPreview: View { struct CameraCellPreview: View {
@Environment(\.router) var router @Environment(\.router) var router
@EnvironmentObject var conversation: ConversationStore
@EnvironmentObject var store: AttachmentsStore @EnvironmentObject var store: AttachmentsStore
var body: some View { var body: some View {
@ -24,8 +25,13 @@ struct CameraCellPreview: View {
} }
.onTapGesture { .onTapGesture {
router.showScreen(.fullScreenCover) { _ in router.showScreen(.fullScreenCover) { _ in
CameraPicker() CameraPicker { data, type in
.ignoresSafeArea(.all) Task {
await conversation.sendCaptured(data, type)
}
router.dismissEnvironment()
}
.ignoresSafeArea(.all)
} }
} }
} else { } else {

View file

@ -3,8 +3,7 @@ import Photos
import SwiftUI import SwiftUI
struct CameraPicker: UIViewControllerRepresentable { struct CameraPicker: UIViewControllerRepresentable {
// var sourceType: UIImagePickerController.SourceType var completionHandler: (Data, GalleryMediaType) -> Void
// var completionHandler: (Data, SharingCameraMediaType) -> Void
func makeUIViewController(context: Context) -> UIImagePickerController { func makeUIViewController(context: Context) -> UIImagePickerController {
let picker = UIImagePickerController() let picker = UIImagePickerController()
@ -34,17 +33,17 @@ struct CameraPicker: UIViewControllerRepresentable {
// swiftlint:disable:next force_cast // swiftlint:disable:next force_cast
let mediaType = info[.mediaType] as! String let mediaType = info[.mediaType] as! String
// if mediaType == UTType.image.identifier { if mediaType == UTType.image.identifier {
// if let image = info[.originalImage] as? UIImage { if let image = info[.originalImage] as? UIImage {
// let data = image.jpegData(compressionQuality: 1.0) ?? Data() let data = image.jpegData(compressionQuality: 1.0) ?? Data()
// parent.completionHandler(data, .photo) parent.completionHandler(data, .photo)
// } }
// } else if mediaType == UTType.movie.identifier { } else if mediaType == UTType.movie.identifier {
// if let url = info[.mediaURL] as? URL { if let url = info[.mediaURL] as? URL {
// let data = try? Data(contentsOf: url) let data = try? Data(contentsOf: url)
// parent.completionHandler(data ?? Data(), .video) parent.completionHandler(data ?? Data(), .video)
// } }
// } }
} }
} }
} }