From 3fc7fc64ae74d1f45b39e85578d6ac3c390e8040 Mon Sep 17 00:00:00 2001 From: shannon Date: Mon, 10 Mar 2025 09:49:43 -0400 Subject: [PATCH] Show non-public visibility indicator in author header --- .../View/Content/StatusAuthorView.swift | 29 ++++++++++++++----- .../View/Content/StatusView+ViewModel.swift | 13 +++++++++ 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/MastodonSDK/Sources/MastodonUI/View/Content/StatusAuthorView.swift b/MastodonSDK/Sources/MastodonUI/View/Content/StatusAuthorView.swift index 51c08ff20..abbaacd90 100644 --- a/MastodonSDK/Sources/MastodonUI/View/Content/StatusAuthorView.swift +++ b/MastodonSDK/Sources/MastodonUI/View/Content/StatusAuthorView.swift @@ -30,8 +30,16 @@ public class StatusAuthorView: UIStackView { // author username public let authorUsernameLabel = MetaLabel(style: .statusUsername) - - public let usernameTrialingDotLabel: MetaLabel = { + + public let visibilityIcon: UIImageView = { + var imageView = UIImageView() + imageView.tintColor = Asset.Colors.Label.secondary.color + var config = UIImage.SymbolConfiguration(font: UIFont.systemFont(ofSize: 15, weight: .regular)) + imageView.preferredSymbolConfiguration = config + return imageView + }() + + public let timestampTrialingDotLabel: MetaLabel = { let label = MetaLabel(style: .statusUsername) label.configure(content: PlaintextMetaContent(string: "ยท")) return label @@ -305,19 +313,26 @@ extension StatusAuthorView { menuButton.setContentHuggingPriority(.required - 1, for: .horizontal) menuButton.setContentCompressionResistancePriority(.required - 1, for: .horizontal) - // authorSecondaryMetaContainer: H - [ authorUsername | usernameTrialingDotLabel | dateLabel | (padding) | contentSensitiveeToggleButton ] + // authorSecondaryMetaContainer: H - [ visibilityIcon | dateLabel | dot | authorUsername | spacer ] let authorSecondaryMetaContainer = UIStackView() authorSecondaryMetaContainer.axis = .horizontal authorSecondaryMetaContainer.alignment = .center authorSecondaryMetaContainer.spacing = 4 authorMetaContainer.addArrangedSubview(authorSecondaryMetaContainer) - + + authorSecondaryMetaContainer.addArrangedSubview(visibilityIcon) + visibilityIcon.setContentCompressionResistancePriority(.required, for: .horizontal) + authorSecondaryMetaContainer.addArrangedSubview(dateLabel) dateLabel.setContentHuggingPriority(.required - 1, for: .horizontal) dateLabel.setContentCompressionResistancePriority(.required - 1, for: .horizontal) + + NSLayoutConstraint.activate([ + visibilityIcon.firstBaselineAnchor.constraint(equalTo: dateLabel.firstBaselineAnchor) + ]) - authorSecondaryMetaContainer.addArrangedSubview(usernameTrialingDotLabel) - usernameTrialingDotLabel.setContentCompressionResistancePriority(.required, for: .horizontal) + authorSecondaryMetaContainer.addArrangedSubview(timestampTrialingDotLabel) + timestampTrialingDotLabel.setContentCompressionResistancePriority(.required, for: .horizontal) authorSecondaryMetaContainer.addArrangedSubview(authorUsernameLabel) authorUsernameLabel.setContentHuggingPriority(.required - 1, for: .vertical) @@ -351,7 +366,7 @@ extension StatusAuthorView { avatarButton.isUserInteractionEnabled = false menuButton.removeFromSuperview() - usernameTrialingDotLabel.removeFromSuperview() dateLabel.removeFromSuperview() + timestampTrialingDotLabel.removeFromSuperview() } } diff --git a/MastodonSDK/Sources/MastodonUI/View/Content/StatusView+ViewModel.swift b/MastodonSDK/Sources/MastodonUI/View/Content/StatusView+ViewModel.swift index 59de2de15..fa628c16d 100644 --- a/MastodonSDK/Sources/MastodonUI/View/Content/StatusView+ViewModel.swift +++ b/MastodonSDK/Sources/MastodonUI/View/Content/StatusView+ViewModel.swift @@ -228,6 +228,19 @@ extension StatusView.ViewModel { authorView.avatarButton.avatarImageView.configure(cornerConfiguration: .init(corner: .fixed(radius: 12))) } .store(in: &disposeBag) + // visibility + $visibility + .sink { visibility in + authorView.visibilityIcon.image = visibility.image + authorView.visibilityIcon.accessibilityLabel = visibility.title + switch visibility { + case .public, ._other: + authorView.visibilityIcon.isHidden = true + case .direct, .private, .unlisted: + authorView.visibilityIcon.isHidden = false + } + } + .store(in: &disposeBag) // name $authorName .sink { metaContent in