diff --git a/Mastodon/Scene/Profile/Header/View/ProfileHeaderView+ViewModel.swift b/Mastodon/Scene/Profile/Header/View/ProfileHeaderView+ViewModel.swift index c5389958a..961a8269a 100644 --- a/Mastodon/Scene/Profile/Header/View/ProfileHeaderView+ViewModel.swift +++ b/Mastodon/Scene/Profile/Header/View/ProfileHeaderView+ViewModel.swift @@ -150,7 +150,9 @@ extension ProfileHeaderView.ViewModel { // username $acct .map { acct in acct.flatMap { "@" + $0 } ?? " " } - .assign(to: \.text, on: view.usernameLabel) + .sink(receiveValue: { acct in + view.usernameButton.setTitle(acct, for: .normal) + }) .store(in: &disposeBag) // bio Publishers.CombineLatest4( diff --git a/Mastodon/Scene/Profile/Header/View/ProfileHeaderView.swift b/Mastodon/Scene/Profile/Header/View/ProfileHeaderView.swift index 5204cf567..322c3be01 100644 --- a/Mastodon/Scene/Profile/Header/View/ProfileHeaderView.swift +++ b/Mastodon/Scene/Profile/Header/View/ProfileHeaderView.swift @@ -172,15 +172,26 @@ final class ProfileHeaderView: UIView { textField.autocapitalizationType = .none return textField }() - - let usernameLabel: UILabel = { - let label = UILabel() - label.font = UIFontMetrics(forTextStyle: .callout).scaledFont(for: .systemFont(ofSize: 16, weight: .regular)) - label.adjustsFontSizeToFitWidth = true - label.minimumScaleFactor = 0.5 - label.textColor = Asset.Colors.Label.secondary.color - label.text = "@alice" - return label + + private lazy var usernameButtonMenu: UIMenu = { + UIMenu(children: [ + UIAction(title: L10n.Common.Controls.Actions.copy, image: UIImage(systemName: "doc.on.doc"), handler: { [weak self] _ in + UIPasteboard.general.string = self?.usernameButton.title(for: .normal) + }) + ]) + }() + + lazy var usernameButton: UIButton = { + let button = UIButton() + button.setTitle("@alice", for: .normal) + button.titleLabel?.font = UIFontMetrics(forTextStyle: .callout).scaledFont(for: .systemFont(ofSize: 16, weight: .regular)) + button.titleLabel?.adjustsFontSizeToFitWidth = true + button.titleLabel?.minimumScaleFactor = 0.5 + button.setTitleColor(Asset.Colors.Label.secondary.color, for: .normal) + button.menu = usernameButtonMenu + button.showsMenuAsPrimaryAction = true + button.setContentCompressionResistancePriority(.defaultLow, for: .horizontal) + return button }() let statusDashboardView = ProfileStatusDashboardView() @@ -417,7 +428,11 @@ extension ProfileHeaderView { // nameMetaText.textView.setContentHuggingPriority(, for: <#T##NSLayoutConstraint.Axis#>) nameContainerStackView.addArrangedSubview(displayNameStackView) - nameContainerStackView.addArrangedSubview(usernameLabel) + nameContainerStackView.addArrangedSubview(usernameButton) + + NSLayoutConstraint.activate([ + usernameButton.heightAnchor.constraint(greaterThanOrEqualToConstant: 20) + ]) authorContainer.addArrangedSubview(nameContainerStackView) authorContainer.addArrangedSubview(UIView())