mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
Move waypoint deep linking into onchange event
This commit is contained in:
parent
e2872b34c9
commit
3424523d98
1 changed files with 26 additions and 23 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue