From 1807eabcb8b924315aaaca7520973ff0c5e83081 Mon Sep 17 00:00:00 2001 From: Jon Parise Date: Fri, 15 Nov 2024 22:29:18 -0500 Subject: [PATCH] macos: prefer private View structs to functions --- macos/Sources/Features/About/AboutView.swift | 66 ++++++++++++-------- 1 file changed, 41 insertions(+), 25 deletions(-) diff --git a/macos/Sources/Features/About/AboutView.swift b/macos/Sources/Features/About/AboutView.swift index 90792d1cf..dcadeaa96 100644 --- a/macos/Sources/Features/About/AboutView.swift +++ b/macos/Sources/Features/About/AboutView.swift @@ -64,14 +64,14 @@ struct AboutView: View { VStack(spacing: 2) { if let version { - propertyRow("Version", text: version) + PropertyRow(label: "Version", text: version) } if let build { - propertyRow("Build", text: build) + PropertyRow(label: "Build", text: build) } if let commit, commit != "", let url = githubURL?.appendingPathComponent("/commits/\(commit)") { - propertyRow("Commit", text: commit, url: url) + PropertyRow(label: "Commit", text: commit, url: url) } } .frame(maxWidth: .infinity) @@ -105,31 +105,47 @@ struct AboutView: View { #endif } - private func propertyRow(_ label: LocalizedStringResource, text: String, url: URL? = nil) -> some View { - HStack(spacing: 4) { - Text(label) - .frame(width: 126, alignment: .trailing) - .padding(.trailing, 2) - if let url { - Link(destination: url) { - propertyText(text) - } - } else { - propertyText(text) - } + private struct PropertyRow: View { + let label: String + let text: String + let url: URL? + + init(label: String, text: String, url: URL? = nil) { + self.label = label + self.text = text + self.url = url + } + + 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 { - Text(text) - .frame(width: 125, alignment: .leading) - .padding(.leading, 2) - .tint(.secondary) - .opacity(0.8) - .monospaced() + private struct PropertyText: View { + let text: String + + var body: some View { + Text(text) + .frame(width: 125, alignment: .leading) + .padding(.leading, 2) + .tint(.secondary) + .opacity(0.8) + .monospaced() + } } }