Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revert the last heard text changes on the list view, since that impacts performace #779

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions Meshtastic/Views/Helpers/LastHeardText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,9 @@ import SwiftUI
struct LastHeardText: View {
var lastHeard: Date?

static let formatter: RelativeDateTimeFormatter = {
let formatter = RelativeDateTimeFormatter()
formatter.unitsStyle = .full
return formatter
}()

var body: some View {
if let lastHeard, lastHeard.timeIntervalSince1970 > 0, let text = Self.formatter.string(for: lastHeard) {
Text(text)
if let lastHeard, lastHeard.timeIntervalSince1970 > 0 {
Text(lastHeard.formatted())
} else {
Text("unknown")
}
Expand Down
29 changes: 24 additions & 5 deletions Meshtastic/Views/Nodes/Helpers/NodeDetail.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@ import CoreLocation
import OSLog

struct NodeDetail: View {
private static let relativeFormatter: RelativeDateTimeFormatter = {
let formatter = RelativeDateTimeFormatter()
formatter.unitsStyle = .full
return formatter
}()

@Environment(\.managedObjectContext) var context
@EnvironmentObject var bleManager: BLEManager
@State private var showingShutdownConfirm: Bool = false
@State private var showingRebootConfirm: Bool = false
@State private var dateFormatRelative: Bool = true

// The node the device is currently connected to
var connectedNode: NodeInfoEntity?
Expand Down Expand Up @@ -138,9 +144,15 @@ struct NodeDetail: View {
.symbolRenderingMode(.multicolor)
}
Spacer()

LastHeardText(lastHeard: firstHeard)
.textSelection(.enabled)
if dateFormatRelative, let text = Self.relativeFormatter.string(for: firstHeard) {
Text(text)
.textSelection(.enabled)
} else {
Text(firstHeard.formatted())
.textSelection(.enabled)
}
}.onTapGesture {
dateFormatRelative.toggle()
}
}

Expand All @@ -154,8 +166,15 @@ struct NodeDetail: View {
}
Spacer()

LastHeardText(lastHeard: lastHeard)
.textSelection(.enabled)
if dateFormatRelative, let text = Self.relativeFormatter.string(for: lastHeard) {
Text(text)
.textSelection(.enabled)
} else {
Text(lastHeard.formatted())
.textSelection(.enabled)
}
}.onTapGesture {
dateFormatRelative.toggle()
}
}
}
Expand Down