diff --git a/ConversationsClassic/View/Screens/Attachments/AttachmentFilesPickerView.swift b/ConversationsClassic/View/Screens/Attachments/AttachmentFilesPickerView.swift index 4a7738f..ec8f490 100644 --- a/ConversationsClassic/View/Screens/Attachments/AttachmentFilesPickerView.swift +++ b/ConversationsClassic/View/Screens/Attachments/AttachmentFilesPickerView.swift @@ -2,23 +2,15 @@ import SwiftUI import UIKit struct AttachmentFilesPickerView: View { - @State private var isPickerPresented = false - var body: some View { - Button { - isPickerPresented = true - } label: { - Text("Select Files") - } - .sheet(isPresented: $isPickerPresented) { - DocumentPicker() - } + DocumentPicker() } } struct DocumentPicker: UIViewControllerRepresentable { func makeUIViewController(context: UIViewControllerRepresentableContext) -> UIDocumentPickerViewController { - let picker = UIDocumentPickerViewController(documentTypes: ["public.item"], in: .import) + let picker: UIDocumentPickerViewController + picker = UIDocumentPickerViewController(forOpeningContentTypes: [.item], asCopy: true) picker.delegate = context.coordinator picker.allowsMultipleSelection = true return picker @@ -38,6 +30,7 @@ struct DocumentPicker: UIViewControllerRepresentable { } func documentPicker(_: UIDocumentPickerViewController, didPickDocumentsAt _: [URL]) { + // TODO: Send documents // Handle the selected files } diff --git a/ConversationsClassic/View/Screens/Attachments/AttachmentLocationPickerView.swift b/ConversationsClassic/View/Screens/Attachments/AttachmentLocationPickerView.swift index 3ed9c4d..c82c05f 100644 --- a/ConversationsClassic/View/Screens/Attachments/AttachmentLocationPickerView.swift +++ b/ConversationsClassic/View/Screens/Attachments/AttachmentLocationPickerView.swift @@ -1,8 +1,10 @@ +import CoreLocation import MapKit import SwiftUI import UIKit struct AttachmentLocationPickerView: View { + @StateObject private var locationManager = LocationManager() @State private var region = MKCoordinateRegion( center: CLLocationCoordinate2D(latitude: 34.011_286, longitude: -116.166_868), span: MKCoordinateSpan(latitudeDelta: 0.2, longitudeDelta: 0.2) @@ -10,6 +12,33 @@ struct AttachmentLocationPickerView: View { var body: some View { MapView(coordinateRegion: $region) + .onAppear { + locationManager.start() + } + .onChange(of: locationManager.lastLocation) { newLocation in + if let newLocation { + region.center = newLocation.coordinate + } + } + } +} + +class LocationManager: NSObject, ObservableObject, CLLocationManagerDelegate { + private let locationManager = CLLocationManager() + @Published var lastLocation: CLLocation? + + override init() { + super.init() + locationManager.delegate = self + } + + func start() { + locationManager.requestWhenInUseAuthorization() + locationManager.startUpdatingLocation() + } + + func locationManager(_: CLLocationManager, didUpdateLocations locations: [CLLocation]) { + lastLocation = locations.first } } diff --git a/ConversationsClassic/View/Screens/Attachments/AttachmentMediaPickerView.swift b/ConversationsClassic/View/Screens/Attachments/AttachmentMediaPickerView.swift index aef2520..7c8a34b 100644 --- a/ConversationsClassic/View/Screens/Attachments/AttachmentMediaPickerView.swift +++ b/ConversationsClassic/View/Screens/Attachments/AttachmentMediaPickerView.swift @@ -96,6 +96,7 @@ struct AttachmentMediaPickerView: View { } .fullScreenCover(isPresented: $showCameraPicker) { CameraPicker(sourceType: .camera) { _ in + // TODO: Send captures photo/video print("Image captured") showCameraPicker = false } @@ -121,6 +122,7 @@ struct AttachmentMediaPickerView: View { } .clipped() .onTapGesture { + // TODO: Send selected media print("Send media files") } }