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)
// }
}
func sendCaptured(_ data: Data, _ type: GalleryMediaType) async {
print("captured!", data, type)
}
}
private extension ConversationStore {

View file

@ -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,7 +25,12 @@ struct CameraCellPreview: View {
}
.onTapGesture {
router.showScreen(.fullScreenCover) { _ in
CameraPicker()
CameraPicker { data, type in
Task {
await conversation.sendCaptured(data, type)
}
router.dismissEnvironment()
}
.ignoresSafeArea(.all)
}
}

View file

@ -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)
}
}
}
}
}