Meshtastic-Apple/Meshtastic/Views/Nodes/Helpers/EditNodeDisplayNameView.swift
Meshtastic Contributor 59ff5ba96a feat: local display names for nodes
- Add NodeDisplayNameStore (UserDefaults) keyed by node number
- Add displayLongName/displayShortName on UserEntity
- Show custom name in node list, detail, messages, relay text
- Add EditNodeDisplayNameView sheet and 'Set display name' in list/detail
- Notify UI on change via NodeDisplayNameStore.didChangeNotification

Made-with: Cursor
2026-03-08 20:44:00 +00:00

60 lines
1.5 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// EditNodeDisplayNameView.swift
// Meshtastic
//
// Sheet to set or clear a local display name for a node.
//
import SwiftUI
import CoreData
struct EditNodeDisplayNameView: View {
@Environment(\.dismiss) private var dismiss
let node: NodeInfoEntity
@State private var displayName: String = ""
@State private var hasChanges: Bool = false
var body: some View {
NavigationStack {
Form {
Section {
TextField("Display name", text: $displayName)
.autocorrectionDisabled(true)
.onChange(of: displayName) { _, _ in hasChanges = true }
} footer: {
Text("This name is only shown on this device. The nodes real name is unchanged for sharing and export.")
}
if NodeDisplayNameStore.displayName(for: node.num) != nil {
Section {
Button(role: .destructive) {
displayName = ""
hasChanges = true
} label: {
Label("Remove custom name", systemImage: "trash")
}
}
}
}
.navigationTitle("Display name")
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .cancellationAction) {
Button("Cancel") {
dismiss()
}
}
ToolbarItem(placement: .confirmationAction) {
Button("Save") {
let trimmed = displayName.trimmingCharacters(in: .whitespacesAndNewlines)
NodeDisplayNameStore.setDisplayName(trimmed.isEmpty ? nil : trimmed, for: node.num)
dismiss()
}
.disabled(!hasChanges)
}
}
.onAppear {
displayName = NodeDisplayNameStore.displayName(for: node.num) ?? ""
}
}
}
}