Merge pull request #856 from mastodon/IOS-8_Tap-to-copy-Username
feat(profile): Implement tap to copy username
This commit is contained in:
commit
823a15fcae
|
@ -150,7 +150,9 @@ extension ProfileHeaderView.ViewModel {
|
||||||
// username
|
// username
|
||||||
$acct
|
$acct
|
||||||
.map { acct in acct.flatMap { "@" + $0 } ?? " " }
|
.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)
|
.store(in: &disposeBag)
|
||||||
// bio
|
// bio
|
||||||
Publishers.CombineLatest4(
|
Publishers.CombineLatest4(
|
||||||
|
|
|
@ -172,15 +172,26 @@ final class ProfileHeaderView: UIView {
|
||||||
textField.autocapitalizationType = .none
|
textField.autocapitalizationType = .none
|
||||||
return textField
|
return textField
|
||||||
}()
|
}()
|
||||||
|
|
||||||
let usernameLabel: UILabel = {
|
private lazy var usernameButtonMenu: UIMenu = {
|
||||||
let label = UILabel()
|
UIMenu(children: [
|
||||||
label.font = UIFontMetrics(forTextStyle: .callout).scaledFont(for: .systemFont(ofSize: 16, weight: .regular))
|
UIAction(title: L10n.Common.Controls.Actions.copy, image: UIImage(systemName: "doc.on.doc"), handler: { [weak self] _ in
|
||||||
label.adjustsFontSizeToFitWidth = true
|
UIPasteboard.general.string = self?.usernameButton.title(for: .normal)
|
||||||
label.minimumScaleFactor = 0.5
|
})
|
||||||
label.textColor = Asset.Colors.Label.secondary.color
|
])
|
||||||
label.text = "@alice"
|
}()
|
||||||
return label
|
|
||||||
|
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()
|
let statusDashboardView = ProfileStatusDashboardView()
|
||||||
|
@ -417,7 +428,11 @@ extension ProfileHeaderView {
|
||||||
// nameMetaText.textView.setContentHuggingPriority(, for: <#T##NSLayoutConstraint.Axis#>)
|
// nameMetaText.textView.setContentHuggingPriority(, for: <#T##NSLayoutConstraint.Axis#>)
|
||||||
|
|
||||||
nameContainerStackView.addArrangedSubview(displayNameStackView)
|
nameContainerStackView.addArrangedSubview(displayNameStackView)
|
||||||
nameContainerStackView.addArrangedSubview(usernameLabel)
|
nameContainerStackView.addArrangedSubview(usernameButton)
|
||||||
|
|
||||||
|
NSLayoutConstraint.activate([
|
||||||
|
usernameButton.heightAnchor.constraint(greaterThanOrEqualToConstant: 20)
|
||||||
|
])
|
||||||
|
|
||||||
authorContainer.addArrangedSubview(nameContainerStackView)
|
authorContainer.addArrangedSubview(nameContainerStackView)
|
||||||
authorContainer.addArrangedSubview(UIView())
|
authorContainer.addArrangedSubview(UIView())
|
||||||
|
|
Loading…
Reference in New Issue