1
0
mirror of https://github.com/mastodon/mastodon-ios.git synced 2025-02-02 18:36:44 +01:00

feat(profile): Implement tap to copy username

This commit is contained in:
Marcus Kida 2023-01-04 16:26:45 +01:00
parent 29cfbea1ef
commit 2866721ca3
No known key found for this signature in database
GPG Key ID: 19FF64E08013CA40
2 changed files with 28 additions and 11 deletions

View File

@ -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(

View File

@ -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, 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(equalToConstant: 20)
])
authorContainer.addArrangedSubview(nameContainerStackView)
authorContainer.addArrangedSubview(UIView())