From 385b3e6a74af3d74ab693263773e43d26e4c91ce Mon Sep 17 00:00:00 2001 From: fmodf Date: Thu, 4 Jul 2024 12:40:27 +0200 Subject: [PATCH] wip --- .../AttachmentMediaPickerView.swift | 49 +++++++++++++++++++ project.yml | 1 + 2 files changed, 50 insertions(+) diff --git a/ConversationsClassic/View/Screens/Attachments/AttachmentMediaPickerView.swift b/ConversationsClassic/View/Screens/Attachments/AttachmentMediaPickerView.swift index 14264a1..aef2520 100644 --- a/ConversationsClassic/View/Screens/Attachments/AttachmentMediaPickerView.swift +++ b/ConversationsClassic/View/Screens/Attachments/AttachmentMediaPickerView.swift @@ -1,4 +1,5 @@ import AVFoundation +import MobileCoreServices import Photos import SwiftUI @@ -13,6 +14,8 @@ struct AttachmentMediaPickerView: View { @State private var thumbnails = [ThumbnailView]() @State private var selectedMedia = [SelectedMedia]() + @State private var showCameraPicker = false + let gridSize = UIScreen.main.bounds.width / 3 var body: some View { @@ -38,6 +41,9 @@ struct AttachmentMediaPickerView: View { .clipShape(Circle()) .padding(8) } + .onTapGesture { + showCameraPicker = true + } } else { Button { openAppSettings() @@ -88,6 +94,13 @@ struct AttachmentMediaPickerView: View { } } } + .fullScreenCover(isPresented: $showCameraPicker) { + CameraPicker(sourceType: .camera) { _ in + print("Image captured") + showCameraPicker = false + } + .edgesIgnoringSafeArea(.all) + } // Send panel Rectangle() @@ -346,3 +359,39 @@ struct CameraView: UIViewRepresentable { uiView.previewLayer?.frame = uiView.bounds } } + +struct CameraPicker: UIViewControllerRepresentable { + var sourceType: UIImagePickerController.SourceType + var completionHandler: (UIImage) -> Void + + func makeUIViewController(context: Context) -> UIImagePickerController { + let picker = UIImagePickerController() + picker.sourceType = sourceType + picker.delegate = context.coordinator + picker.mediaTypes = [UTType.movie.identifier, UTType.image.identifier] + picker.videoQuality = .typeHigh + picker.videoMaximumDuration = 60 // 60 sec Limit + picker.view.backgroundColor = .clear + return picker + } + + func updateUIViewController(_: UIImagePickerController, context _: Context) {} + + func makeCoordinator() -> Coordinator { + Coordinator(self) + } + + class Coordinator: NSObject, UINavigationControllerDelegate, UIImagePickerControllerDelegate { + let parent: CameraPicker + + init(_ parent: CameraPicker) { + self.parent = parent + } + + func imagePickerController(_: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) { + if let image = info[.originalImage] as? UIImage { + parent.completionHandler(image) + } + } + } +} diff --git a/project.yml b/project.yml index 62fbc10..ddf57b0 100644 --- a/project.yml +++ b/project.yml @@ -43,6 +43,7 @@ targets: NSAllowsArbitraryLoads: true NSPhotoLibraryUsageDescription: Allow app to send photo from gallery in attachments NSCameraUsageDescription: Allow app to take picture from camera and send it in atachments + NSMicrophoneUsageDescription: Allow app to take sound from microphone for attachment video # UIViewControllerBasedStatusBarAppearance: NO # UIStatusBarStyle: UIStatusBarStyleLightContent # NSFaceIDUsageDescription: Required for accessing to account info