This commit is contained in:
fmodf 2024-07-04 14:55:47 +02:00
parent f679c7d357
commit d4e4c18762
2 changed files with 31 additions and 4 deletions

View file

@ -10,14 +10,15 @@ struct AttachmentLocationPickerView: View {
span: MKCoordinateSpan(latitudeDelta: 0.2, longitudeDelta: 0.2) span: MKCoordinateSpan(latitudeDelta: 0.2, longitudeDelta: 0.2)
) )
@State private var showingAlert = false @State private var showingAlert = false
@State private var userInteraction = false
var body: some View { var body: some View {
MapView(coordinateRegion: $region) MapView(coordinateRegion: $region, interactionState: $userInteraction)
.onAppear { .onAppear {
locationManager.start() locationManager.start()
} }
.onChange(of: locationManager.lastLocation) { newLocation in .onChange(of: locationManager.lastLocation) { newLocation in
if let newLocation { if let newLocation, !userInteraction {
region.center = newLocation.coordinate 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 { struct MapView: UIViewRepresentable {
@Binding var coordinateRegion: MKCoordinateRegion @Binding var coordinateRegion: MKCoordinateRegion
@Binding var interactionState: Bool
func makeUIView(context: Context) -> MKMapView { func makeUIView(context: Context) -> MKMapView {
let mapView = MKMapView() let mapView = MKMapView()
mapView.delegate = context.coordinator mapView.delegate = context.coordinator
mapView.addGestureRecognizer(UIPanGestureRecognizer(target: context.coordinator, action: #selector(Coordinator.mapWasDragged)))
return mapView return mapView
} }
@ -87,8 +112,8 @@ struct MapView: UIViewRepresentable {
self.parent = parent self.parent = parent
} }
func mapView(_ mapView: MKMapView, regionDidChangeAnimated _: Bool) { @objc func mapWasDragged() {
parent.coordinateRegion = mapView.region parent.interactionState = true
} }
} }
} }

View file

@ -44,6 +44,8 @@ targets:
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 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 # UIViewControllerBasedStatusBarAppearance: NO
# UIStatusBarStyle: UIStatusBarStyleLightContent # UIStatusBarStyle: UIStatusBarStyleLightContent
# NSFaceIDUsageDescription: Required for accessing to account info # NSFaceIDUsageDescription: Required for accessing to account info