Move waypoint deep linking into onchange event

This commit is contained in:
Garth Vander Houwen 2024-01-20 19:33:11 -08:00
parent e2872b34c9
commit 3424523d98

View file

@ -253,6 +253,32 @@ struct MeshMap: View {
.sheet(isPresented: $isEditingSettings) {
MapSettingsForm(nodeHistory: $showNodeHistory, routeLines: $showRouteLines, convexHull: $showConvexHull, traffic: $showTraffic, pointsOfInterest: $showPointsOfInterest, mapLayer: $selectedMapLayer)
}
.onChange(of: (appState.navigationPath)) { newPath in
if ((newPath?.hasPrefix("meshtastic://open-waypoint")) != nil) {
guard let url = URL(string: appState.navigationPath ?? "NONE") else {
print("Invalid URL")
return
}
guard let components = URLComponents(url: url, resolvingAgainstBaseURL: true) else {
print("Invalid URL Components")
return
}
guard let action = components.host, action == "open-waypoint" else {
print("Unknown waypoint URL action")
return
}
guard let waypointId = components.queryItems?.first(where: { $0.name == "id" })?.value else {
print("Waypoint id not found")
return
}
guard let waypoint = waypoints.first(where: { $0.id == Int64(waypointId) }) else {
print("Waypoint not found")
return
}
position = .camera(MapCamera(centerCoordinate: waypoint.coordinate, distance: 150, heading: 0, pitch: 60))
}
}
.onChange(of: (selectedMapLayer)) { newMapLayer in
switch selectedMapLayer {
case .standard:
@ -334,29 +360,6 @@ struct MeshMap: View {
case .offline:
mapStyle = MapStyle.hybrid(elevation: .realistic, pointsOfInterest: showPointsOfInterest ? .all : .excludingAll, showsTraffic: showTraffic)
}
if ((appState.navigationPath?.hasPrefix("meshtastic://open-waypoint")) != nil) {
guard let url = URL(string: appState.navigationPath ?? "NONE") else {
print("Invalid URL")
return
}
guard let components = URLComponents(url: url, resolvingAgainstBaseURL: true) else {
print("Invalid URL Components")
return
}
guard let action = components.host, action == "open-waypoint" else {
print("Unknown waypoint URL action")
return
}
guard let waypointId = components.queryItems?.first(where: { $0.name == "id" })?.value else {
print("Waypoint name not found")
return
}
guard let waypoint = waypoints.first(where: { $0.id == Int64(waypointId) }) else {
print("Waypoint name not found")
return
}
position = .camera(MapCamera(centerCoordinate: waypoint.coordinate, distance: 150, heading: 0, pitch: 60))
}
}
.onDisappear(perform: {
UIApplication.shared.isIdleTimerDisabled = false