From d4e4c18762f111915cb77791a708f574441e772c Mon Sep 17 00:00:00 2001 From: fmodf Date: Thu, 4 Jul 2024 14:55:47 +0200 Subject: [PATCH] wip --- .../AttachmentLocationPickerView.swift | 33 ++++++++++++++++--- project.yml | 2 ++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/ConversationsClassic/View/Screens/Attachments/AttachmentLocationPickerView.swift b/ConversationsClassic/View/Screens/Attachments/AttachmentLocationPickerView.swift index 29addfc..c40af55 100644 --- a/ConversationsClassic/View/Screens/Attachments/AttachmentLocationPickerView.swift +++ b/ConversationsClassic/View/Screens/Attachments/AttachmentLocationPickerView.swift @@ -10,14 +10,15 @@ struct AttachmentLocationPickerView: View { span: MKCoordinateSpan(latitudeDelta: 0.2, longitudeDelta: 0.2) ) @State private var showingAlert = false + @State private var userInteraction = false var body: some View { - MapView(coordinateRegion: $region) + MapView(coordinateRegion: $region, interactionState: $userInteraction) .onAppear { locationManager.start() } .onChange(of: locationManager.lastLocation) { newLocation in - if let newLocation { + if let newLocation, !userInteraction { region.center = newLocation.coordinate } } @@ -35,6 +36,28 @@ struct AttachmentLocationPickerView: View { } ) } + .overlay { + Image(systemName: "mappin") + .font(.title) + .foregroundColor(.Material.Elements.active) + .padding() + if userInteraction { + VStack { + Spacer() + HStack { + Spacer() + Image(systemName: "location.north.circle.fill") + .font(.title) + .foregroundColor(.Material.Elements.active) + .padding() + .tappablePadding(.symmetric(10)) { + userInteraction = false + region.center = locationManager.lastLocation?.coordinate ?? region.center + } + } + } + } + } } } @@ -65,10 +88,12 @@ class LocationManager: NSObject, ObservableObject, CLLocationManagerDelegate { struct MapView: UIViewRepresentable { @Binding var coordinateRegion: MKCoordinateRegion + @Binding var interactionState: Bool func makeUIView(context: Context) -> MKMapView { let mapView = MKMapView() mapView.delegate = context.coordinator + mapView.addGestureRecognizer(UIPanGestureRecognizer(target: context.coordinator, action: #selector(Coordinator.mapWasDragged))) return mapView } @@ -87,8 +112,8 @@ struct MapView: UIViewRepresentable { self.parent = parent } - func mapView(_ mapView: MKMapView, regionDidChangeAnimated _: Bool) { - parent.coordinateRegion = mapView.region + @objc func mapWasDragged() { + parent.interactionState = true } } } diff --git a/project.yml b/project.yml index ddf57b0..e95f55d 100644 --- a/project.yml +++ b/project.yml @@ -44,6 +44,8 @@ targets: 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 + NSLocationWhenInUseUsageDescription: Allow app to take your geo to send it in attachment + NSLocationAlwaysAndWhenInUseUsageDescription: Allow app to take your geo to send it in attachment # UIViewControllerBasedStatusBarAppearance: NO # UIStatusBarStyle: UIStatusBarStyleLightContent # NSFaceIDUsageDescription: Required for accessing to account info