Meshtastic-Apple/Meshtastic/Extensions/View.swift
Copilot bac376edcb
Implement map legend overlay (#1653)
* Add map legend feature (issue #924)

Implement a map legend overlay accessible from both the mesh map and node
detail map views. The legend explains all visual map elements including:
- Online/offline node markers with pulsing animation
- Detection sensor nodes
- Waypoints
- Position precision circles
- Position history points and heading arrows
- Route start/end markers and route lines
- Convex hull mesh coverage outline

A new "map" button is added to the floating control buttons on both map
views, opening the legend as a sheet.

Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Apple/sessions/23f75e1e-549b-46a1-84c9-fb0a6375dcd9

Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com>

* Improve legend descriptions for online/offline nodes

Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Apple/sessions/23f75e1e-549b-46a1-84c9-fb0a6375dcd9

Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com>

* map button glass and cleanup

* Update Meshtastic/Views/Nodes/Helpers/Map/MapLegend.swift

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update incorect online timeframe

* Update Meshtastic/Views/Nodes/MeshMap.swift

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update Meshtastic/Views/Nodes/Helpers/Map/NodeMapSwiftUI.swift

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* translation file

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com>
Co-authored-by: Garth Vander Houwen <garthvh@yahoo.com>
Co-authored-by: Garth Vander Houwen <garth@meshtastic.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-04-05 14:40:54 -07:00

77 lines
1.7 KiB
Swift

//
// View.swift
// Meshtastic
//
// Copyright(c) Garth Vander Houwen 8/14/24.
//
import SwiftUI
extension View {
func onFirstAppear(_ action: @escaping () -> Void) -> some View {
modifier(FirstAppear(action: action))
}
@ViewBuilder func olderThanOS26( _ contentBuilder: (@escaping (Self) -> some View) ) -> some View {
if #available(iOS 26.0, macOS 26.0, *) {
self
} else {
contentBuilder(self)
}
}
/// Conditionally applies `defaultScrollAnchor` only on iOS 18+.
@ViewBuilder
func defaultScrollAnchorTopAlignment() -> some View {
if #available(iOS 18, macOS 15, *) {
AnyView(self.defaultScrollAnchor(.top, for: .alignment))
} else {
AnyView(self)
}
}
/// Conditionally applies `defaultScrollAnchor` only on iOS 18+.
@ViewBuilder
func defaultScrollAnchorBottomSizeChanges() -> some View {
if #available(iOS 18, macOS 15, *) {
AnyView(self.defaultScrollAnchor(.bottom, for: .sizeChanges))
} else {
AnyView(self)
}
}
@ViewBuilder func `if`<Content: View>(_ condition: @autoclosure () -> Bool, transform: (Self) -> Content) -> some View {
if condition() {
transform(self)
} else {
self
}
}
@ViewBuilder
func glassButtonStyle() -> some View {
if #available(iOS 26.0, macOS 26.0, *) {
self.buttonStyle(.glass)
} else {
self
.tint(Color(UIColor.secondarySystemBackground))
.foregroundColor(.accentColor)
.buttonStyle(.borderedProminent)
}
}
}
private struct FirstAppear: ViewModifier {
let action: () -> Void
// Use this to only fire your block one time
@State private var hasAppeared = false
func body(content: Content) -> some View {
// And then, track it here
content.onAppear {
guard !hasAppeared else { return }
hasAppeared = true
action()
}
}
}