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

View file

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

View file

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