diff --git a/iOS/Settings/AboutView.swift b/iOS/Settings/AboutView.swift index 59cf94b13..1de93d704 100644 --- a/iOS/Settings/AboutView.swift +++ b/iOS/Settings/AboutView.swift @@ -7,6 +7,7 @@ // import SwiftUI +import RSCore struct AboutView: View { var body: some View { @@ -20,8 +21,9 @@ struct AboutView: View { Text(verbatim: "NetNewsWire") .font(.largeTitle) + CopyableText(text: "Version \(Bundle.main.versionNumber) (build \(Bundle.main.buildNumber))") + Text(verbatim: "By Brent Simmons and the NetNewsWire team") - .foregroundStyle(.secondary) Text("[netnewswire.com](https://netnewswire.com/)") VStack(spacing: 6) { diff --git a/iOS/Settings/SettingsViewController.swift b/iOS/Settings/SettingsViewController.swift index af2d2ca58..130cf8fbb 100644 --- a/iOS/Settings/SettingsViewController.swift +++ b/iOS/Settings/SettingsViewController.swift @@ -150,14 +150,11 @@ final class SettingsViewController: UITableViewController { openLinksInNetNewsWire.isOn = !AppDefaults.shared.useSystemBrowser - let buildLabel = NonIntrinsicLabel(frame: CGRect(x: 32.0, y: 0.0, width: 0.0, height: 0.0)) + let buildLabel = CopyableLabel(frame: CGRect(x: 32.0, y: 0.0, width: 0.0, height: 0.0)) buildLabel.font = UIFont.systemFont(ofSize: 11.0) buildLabel.textColor = UIColor.gray - buildLabel.text = versionString + buildLabel.text = "\(Bundle.main.appName) \(Bundle.main.versionNumber) (build \(Bundle.main.buildNumber))" buildLabel.sizeToFit() - buildLabel.isUserInteractionEnabled = true - buildLabel.addInteraction(UIEditMenuInteraction(delegate: self)) - buildLabel.addGestureRecognizer(UILongPressGestureRecognizer(target: self, action: #selector(showVersionEditMenu(_:)))) let wrapperView = UIView(frame: CGRect(x: 0, y: 0, width: tableView.bounds.width, height: buildLabel.frame.height + 10.0)) wrapperView.addSubview(buildLabel) @@ -464,39 +461,10 @@ extension SettingsViewController: UIDocumentPickerDelegate { } -// MARK: - Version Edit Menu - -extension SettingsViewController: @preconcurrency UIEditMenuInteractionDelegate { - - func editMenuInteraction(_ interaction: UIEditMenuInteraction, menuFor configuration: UIEditMenuConfiguration, suggestedActions: [UIMenuElement]) -> UIMenu? { - let versionString = versionString - let title = NSLocalizedString("Copy", comment: "Command") - let copyAction = UIAction(title: title) { _ in - UIPasteboard.general.string = versionString - } - return UIMenu(children: [copyAction]) - } -} - // MARK: - Private private extension SettingsViewController { - var versionString: String { - "\(Bundle.main.appName) \(Bundle.main.versionNumber) (Build \(Bundle.main.buildNumber))" - } - - @objc func showVersionEditMenu(_ recognizer: UILongPressGestureRecognizer) { - guard recognizer.state == .began, let label = recognizer.view else { - return - } - guard let editMenuInteraction = label.interactions.first(where: { $0 is UIEditMenuInteraction }) as? UIEditMenuInteraction else { - return - } - let sourcePoint = CGPoint(x: label.bounds.midX, y: label.bounds.minY) - editMenuInteraction.presentEditMenu(with: UIEditMenuConfiguration(identifier: nil, sourcePoint: sourcePoint)) - } - static func makePopUpButton() -> UIButton { var configuration = UIButton.Configuration.plain() configuration.baseForegroundColor = .secondaryLabel diff --git a/iOS/UIKit Extensions/CopyableLabel.swift b/iOS/UIKit Extensions/CopyableLabel.swift new file mode 100644 index 000000000..263ca720b --- /dev/null +++ b/iOS/UIKit Extensions/CopyableLabel.swift @@ -0,0 +1,85 @@ +// +// CopyableLabel.swift +// NetNewsWire-iOS +// +// Created by Brent Simmons on 10/20/26. +// + +import UIKit +import SwiftUI + +/// A label that shows a Copy edit menu on long press. Copy copies the entire text — no selection. +final class CopyableLabel: UILabel { + + override init(frame: CGRect) { + super.init(frame: frame) + commonInit() + } + + required init?(coder: NSCoder) { + super.init(coder: coder) + commonInit() + } +} + +// MARK: - UIEditMenuInteractionDelegate + +extension CopyableLabel: @preconcurrency UIEditMenuInteractionDelegate { + + func editMenuInteraction(_ interaction: UIEditMenuInteraction, menuFor configuration: UIEditMenuConfiguration, suggestedActions: [UIMenuElement]) -> UIMenu? { + let title = NSLocalizedString("Copy", comment: "Command") + let copyAction = UIAction(title: title) { [weak self] _ in + UIPasteboard.general.string = self?.text + } + return UIMenu(children: [copyAction]) + } +} + +// MARK: - Private + +private extension CopyableLabel { + + func commonInit() { + isUserInteractionEnabled = true + addInteraction(UIEditMenuInteraction(delegate: self)) + addGestureRecognizer(UILongPressGestureRecognizer(target: self, action: #selector(showEditMenu(_:)))) + } + + @objc func showEditMenu(_ recognizer: UILongPressGestureRecognizer) { + guard recognizer.state == .began else { + return + } + guard let editMenuInteraction = interactions.first(where: { $0 is UIEditMenuInteraction }) as? UIEditMenuInteraction else { + return + } + let sourcePoint = CGPoint(x: bounds.midX, y: bounds.minY) + editMenuInteraction.presentEditMenu(with: UIEditMenuConfiguration(identifier: nil, sourcePoint: sourcePoint)) + } +} + +// MARK: - SwiftUI + +/// SwiftUI wrapper for `CopyableLabel`: centered, secondary-colored body text. +struct CopyableText: UIViewRepresentable { + + let text: String + + func makeUIView(context: Context) -> CopyableLabel { + let label = CopyableLabel() + label.font = UIFont.preferredFont(forTextStyle: .body) + label.adjustsFontForContentSizeCategory = true + label.textColor = UIColor.secondaryLabel + label.textAlignment = .center + label.numberOfLines = 0 + return label + } + + func updateUIView(_ label: CopyableLabel, context: Context) { + label.text = text + } + + func sizeThatFits(_ proposal: ProposedViewSize, uiView label: CopyableLabel, context: Context) -> CGSize? { + let width = proposal.width ?? CGFloat.greatestFiniteMagnitude + return label.sizeThatFits(CGSize(width: width, height: CGFloat.greatestFiniteMagnitude)) + } +}