This commit is contained in:
fmodf 2024-07-04 13:45:39 +02:00
parent 385b3e6a74
commit b309574c78
3 changed files with 35 additions and 11 deletions

View file

@ -2,23 +2,15 @@ import SwiftUI
import UIKit import UIKit
struct AttachmentFilesPickerView: View { struct AttachmentFilesPickerView: View {
@State private var isPickerPresented = false
var body: some View { var body: some View {
Button {
isPickerPresented = true
} label: {
Text("Select Files")
}
.sheet(isPresented: $isPickerPresented) {
DocumentPicker() DocumentPicker()
} }
}
} }
struct DocumentPicker: UIViewControllerRepresentable { struct DocumentPicker: UIViewControllerRepresentable {
func makeUIViewController(context: UIViewControllerRepresentableContext<DocumentPicker>) -> UIDocumentPickerViewController { func makeUIViewController(context: UIViewControllerRepresentableContext<DocumentPicker>) -> UIDocumentPickerViewController {
let picker = UIDocumentPickerViewController(documentTypes: ["public.item"], in: .import) let picker: UIDocumentPickerViewController
picker = UIDocumentPickerViewController(forOpeningContentTypes: [.item], asCopy: true)
picker.delegate = context.coordinator picker.delegate = context.coordinator
picker.allowsMultipleSelection = true picker.allowsMultipleSelection = true
return picker return picker
@ -38,6 +30,7 @@ struct DocumentPicker: UIViewControllerRepresentable {
} }
func documentPicker(_: UIDocumentPickerViewController, didPickDocumentsAt _: [URL]) { func documentPicker(_: UIDocumentPickerViewController, didPickDocumentsAt _: [URL]) {
// TODO: Send documents
// Handle the selected files // Handle the selected files
} }

View file

@ -1,8 +1,10 @@
import CoreLocation
import MapKit import MapKit
import SwiftUI import SwiftUI
import UIKit import UIKit
struct AttachmentLocationPickerView: View { struct AttachmentLocationPickerView: View {
@StateObject private var locationManager = LocationManager()
@State private var region = MKCoordinateRegion( @State private var region = MKCoordinateRegion(
center: CLLocationCoordinate2D(latitude: 34.011_286, longitude: -116.166_868), center: CLLocationCoordinate2D(latitude: 34.011_286, longitude: -116.166_868),
span: MKCoordinateSpan(latitudeDelta: 0.2, longitudeDelta: 0.2) span: MKCoordinateSpan(latitudeDelta: 0.2, longitudeDelta: 0.2)
@ -10,6 +12,33 @@ struct AttachmentLocationPickerView: View {
var body: some View { var body: some View {
MapView(coordinateRegion: $region) 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
} }
} }

View file

@ -96,6 +96,7 @@ struct AttachmentMediaPickerView: View {
} }
.fullScreenCover(isPresented: $showCameraPicker) { .fullScreenCover(isPresented: $showCameraPicker) {
CameraPicker(sourceType: .camera) { _ in CameraPicker(sourceType: .camera) { _ in
// TODO: Send captures photo/video
print("Image captured") print("Image captured")
showCameraPicker = false showCameraPicker = false
} }
@ -121,6 +122,7 @@ struct AttachmentMediaPickerView: View {
} }
.clipped() .clipped()
.onTapGesture { .onTapGesture {
// TODO: Send selected media
print("Send media files") print("Send media files")
} }
} }