This commit is contained in:
fmodf 2024-07-04 12:40:27 +02:00
parent c2fb21f932
commit 385b3e6a74
2 changed files with 50 additions and 0 deletions

View file

@ -1,4 +1,5 @@
import AVFoundation import AVFoundation
import MobileCoreServices
import Photos import Photos
import SwiftUI import SwiftUI
@ -13,6 +14,8 @@ struct AttachmentMediaPickerView: View {
@State private var thumbnails = [ThumbnailView]() @State private var thumbnails = [ThumbnailView]()
@State private var selectedMedia = [SelectedMedia]() @State private var selectedMedia = [SelectedMedia]()
@State private var showCameraPicker = false
let gridSize = UIScreen.main.bounds.width / 3 let gridSize = UIScreen.main.bounds.width / 3
var body: some View { var body: some View {
@ -38,6 +41,9 @@ struct AttachmentMediaPickerView: View {
.clipShape(Circle()) .clipShape(Circle())
.padding(8) .padding(8)
} }
.onTapGesture {
showCameraPicker = true
}
} else { } else {
Button { Button {
openAppSettings() openAppSettings()
@ -88,6 +94,13 @@ struct AttachmentMediaPickerView: View {
} }
} }
} }
.fullScreenCover(isPresented: $showCameraPicker) {
CameraPicker(sourceType: .camera) { _ in
print("Image captured")
showCameraPicker = false
}
.edgesIgnoringSafeArea(.all)
}
// Send panel // Send panel
Rectangle() Rectangle()
@ -346,3 +359,39 @@ struct CameraView: UIViewRepresentable {
uiView.previewLayer?.frame = uiView.bounds 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)
}
}
}
}

View file

@ -43,6 +43,7 @@ targets:
NSAllowsArbitraryLoads: true NSAllowsArbitraryLoads: true
NSPhotoLibraryUsageDescription: Allow app to send photo from gallery in attachments NSPhotoLibraryUsageDescription: Allow app to send photo from gallery in attachments
NSCameraUsageDescription: Allow app to take picture from camera and send it in atachments 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 # UIViewControllerBasedStatusBarAppearance: NO
# UIStatusBarStyle: UIStatusBarStyleLightContent # UIStatusBarStyle: UIStatusBarStyleLightContent
# NSFaceIDUsageDescription: Required for accessing to account info # NSFaceIDUsageDescription: Required for accessing to account info