macos: prefer private View structs to functions

This commit is contained in:
Jon Parise
2024-11-15 22:29:18 -05:00
parent 6c3eaaf647
commit 1807eabcb8

View File

@ -64,14 +64,14 @@ struct AboutView: View {
VStack(spacing: 2) { VStack(spacing: 2) {
if let version { if let version {
propertyRow("Version", text: version) PropertyRow(label: "Version", text: version)
} }
if let build { if let build {
propertyRow("Build", text: build) PropertyRow(label: "Build", text: build)
} }
if let commit, commit != "", if let commit, commit != "",
let url = githubURL?.appendingPathComponent("/commits/\(commit)") { let url = githubURL?.appendingPathComponent("/commits/\(commit)") {
propertyRow("Commit", text: commit, url: url) PropertyRow(label: "Commit", text: commit, url: url)
} }
} }
.frame(maxWidth: .infinity) .frame(maxWidth: .infinity)
@ -105,31 +105,47 @@ struct AboutView: View {
#endif #endif
} }
private func propertyRow(_ label: LocalizedStringResource, text: String, url: URL? = nil) -> some View { private struct PropertyRow: View {
HStack(spacing: 4) { let label: String
Text(label) let text: String
.frame(width: 126, alignment: .trailing) let url: URL?
.padding(.trailing, 2)
if let url { init(label: String, text: String, url: URL? = nil) {
Link(destination: url) { self.label = label
propertyText(text) self.text = text
} self.url = url
} else { }
propertyText(text)
} var body: some View {
HStack(spacing: 4) {
Text(label)
.frame(width: 126, alignment: .trailing)
.padding(.trailing, 2)
if let url {
Link(destination: url) {
PropertyText(text: text)
}
} else {
PropertyText(text: text)
}
}
.font(.callout)
.textSelection(.enabled)
.frame(maxWidth: .infinity)
} }
.font(.callout)
.textSelection(.enabled)
.frame(maxWidth: .infinity)
} }
private func propertyText(_ text: String) -> some View { private struct PropertyText: View {
Text(text) let text: String
.frame(width: 125, alignment: .leading)
.padding(.leading, 2) var body: some View {
.tint(.secondary) Text(text)
.opacity(0.8) .frame(width: 125, alignment: .leading)
.monospaced() .padding(.leading, 2)
.tint(.secondary)
.opacity(0.8)
.monospaced()
}
} }
} }