From 5fd3215921a5d9cb67763f96b9d99bebae7c1bb5 Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Sun, 15 Jan 2023 09:18:50 -0800 Subject: [PATCH] Prevent waypoint form from opening up with apple park as the location --- Meshtastic/Views/Map/MapViewSwiftUI.swift | 2 +- Meshtastic/Views/Map/WaypointFormView.swift | 3 ++- Meshtastic/Views/Nodes/NodeDetail.swift | 14 ++++++++++---- Meshtastic/Views/Nodes/NodeMap.swift | 10 ++++++---- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/Meshtastic/Views/Map/MapViewSwiftUI.swift b/Meshtastic/Views/Map/MapViewSwiftUI.swift index 4bdd7001..171c9c58 100644 --- a/Meshtastic/Views/Map/MapViewSwiftUI.swift +++ b/Meshtastic/Views/Map/MapViewSwiftUI.swift @@ -181,12 +181,12 @@ struct MapViewSwiftUI: UIViewRepresentable { let location = longPressRecognizer.location(in: self.parent.mapView) // Map Coordinate - CLLocationCoordinate2D let coordinate = self.parent.mapView.convert(location, toCoordinateFrom: self.parent.mapView) + parent.onMarkerTap(coordinate) // Add annotation: let annotation = MKPointAnnotation() annotation.title = "Dropped Pin" annotation.coordinate = coordinate parent.mapView.addAnnotation(annotation) - parent.onMarkerTap(coordinate) UINotificationFeedbackGenerator().notificationOccurred(.success) } diff --git a/Meshtastic/Views/Map/WaypointFormView.swift b/Meshtastic/Views/Map/WaypointFormView.swift index 5d9bf432..0e6712e2 100644 --- a/Meshtastic/Views/Map/WaypointFormView.swift +++ b/Meshtastic/Views/Map/WaypointFormView.swift @@ -11,8 +11,9 @@ import CoreLocation struct WaypointFormView: View { @EnvironmentObject var bleManager: BLEManager - @State var coordinate: CLLocationCoordinate2D @Environment(\.dismiss) private var dismiss + @State var coordinate: CLLocationCoordinate2D + @FocusState private var iconIsFocused: Bool @State private var id: Int32? @State private var name: String = "" diff --git a/Meshtastic/Views/Nodes/NodeDetail.swift b/Meshtastic/Views/Nodes/NodeDetail.swift index e7f54145..71117497 100644 --- a/Meshtastic/Views/Nodes/NodeDetail.swift +++ b/Meshtastic/Views/Nodes/NodeDetail.swift @@ -46,7 +46,11 @@ struct NodeDetail: View { ZStack { MapViewSwiftUI(onMarkerTap: { coord in waypointCoordinate = coord - presentingWaypointForm = true + if waypointCoordinate == nil { + presentingWaypointForm = false + } else { + presentingWaypointForm = true + } }, positions: annotations, waypoints: Array(waypoints), region: MKCoordinateRegion(center: nodeCoordinatePosition, span: MKCoordinateSpan(latitudeDelta: 0.005, longitudeDelta: 0.005)), mapViewType: mapType, customMapOverlay: self.customMapOverlay, overlays: self.overlays @@ -379,9 +383,11 @@ struct NodeDetail: View { } .edgesIgnoringSafeArea([.leading, .trailing]) .sheet(isPresented: $presentingWaypointForm ) {//, onDismiss: didDismissSheet) { - WaypointFormView(coordinate: waypointCoordinate ?? LocationHelper.DefaultLocation) - .presentationDetents([.medium, .large]) - .presentationDragIndicator(.automatic) + if waypointCoordinate != nil { + WaypointFormView(coordinate: waypointCoordinate!) + .presentationDetents([.medium, .large]) + .presentationDragIndicator(.automatic) + } } .navigationBarTitle(String(node.user?.longName ?? NSLocalizedString("unknown", comment: "")), displayMode: .inline) .navigationBarItems(trailing: diff --git a/Meshtastic/Views/Nodes/NodeMap.swift b/Meshtastic/Views/Nodes/NodeMap.swift index 5c52a284..06593a6f 100644 --- a/Meshtastic/Views/Nodes/NodeMap.swift +++ b/Meshtastic/Views/Nodes/NodeMap.swift @@ -53,7 +53,7 @@ struct NodeMap: View { MapViewSwiftUI(onMarkerTap: { coord in waypointCoordinate = coord - if waypointCoordinate?.latitude ?? LocationHelper.DefaultLocation.latitude == LocationHelper.DefaultLocation.latitude { + if waypointCoordinate == nil { presentingWaypointForm = false } else { presentingWaypointForm = true @@ -79,9 +79,11 @@ struct NodeMap: View { .ignoresSafeArea(.all, edges: [.top, .leading, .trailing]) .frame(maxHeight: .infinity) .sheet(isPresented: $presentingWaypointForm ) {//, onDismiss: didDismissSheet) { - WaypointFormView(coordinate: waypointCoordinate ?? LocationHelper.DefaultLocation) - .presentationDetents([.medium, .large]) - .presentationDragIndicator(.automatic) + if waypointCoordinate != nil { + WaypointFormView(coordinate: waypointCoordinate!) + .presentationDetents([.medium, .large]) + .presentationDragIndicator(.automatic) + } } } .navigationBarItems(leading: