From 6315abeb9e32ae9f949bda90e54997d0733ac62f Mon Sep 17 00:00:00 2001 From: Nathan Mattes Date: Sun, 30 Jun 2024 19:47:52 +0200 Subject: [PATCH] Use different labels for publisher and date (IOS-284) so that in case of loooooooooooong publisher names the publisher name is shortened but the date is still visible --- .../input/Base.lproj/app.json | 1 - Localization/app.json | 1 - .../Generated/Strings.swift | 4 -- .../Resources/Base.lproj/Localizable.strings | 1 - .../View/Content/StatusCardControl.swift | 38 +++++++++++++++---- 5 files changed, 30 insertions(+), 15 deletions(-) diff --git a/Localization/StringsConvertor/input/Base.lproj/app.json b/Localization/StringsConvertor/input/Base.lproj/app.json index 710062c52..f11b057a6 100644 --- a/Localization/StringsConvertor/input/Base.lproj/app.json +++ b/Localization/StringsConvertor/input/Base.lproj/app.json @@ -234,7 +234,6 @@ "original_post": "Original Post · %s" }, "card": { - "publisher_date": "%s · %s", "by": "By", "by_author": "By %s" } diff --git a/Localization/app.json b/Localization/app.json index 710062c52..f11b057a6 100644 --- a/Localization/app.json +++ b/Localization/app.json @@ -234,7 +234,6 @@ "original_post": "Original Post · %s" }, "card": { - "publisher_date": "%s · %s", "by": "By", "by_author": "By %s" } diff --git a/MastodonSDK/Sources/MastodonLocalization/Generated/Strings.swift b/MastodonSDK/Sources/MastodonLocalization/Generated/Strings.swift index 1fe0a1283..5bc6b5a72 100644 --- a/MastodonSDK/Sources/MastodonLocalization/Generated/Strings.swift +++ b/MastodonSDK/Sources/MastodonLocalization/Generated/Strings.swift @@ -418,10 +418,6 @@ public enum L10n { public static func byAuthor(_ p1: Any) -> String { return L10n.tr("Localizable", "Common.Controls.Status.Card.ByAuthor", String(describing: p1), fallback: "By %@") } - /// %@ · %@ - public static func publisherDate(_ p1: Any, _ p2: Any) -> String { - return L10n.tr("Localizable", "Common.Controls.Status.Card.PublisherDate", String(describing: p1), String(describing: p2), fallback: "%@ · %@") - } } public enum EditHistory { /// Original Post · %@ diff --git a/MastodonSDK/Sources/MastodonLocalization/Resources/Base.lproj/Localizable.strings b/MastodonSDK/Sources/MastodonLocalization/Resources/Base.lproj/Localizable.strings index 85d1bdd6c..5e708acb7 100644 --- a/MastodonSDK/Sources/MastodonLocalization/Resources/Base.lproj/Localizable.strings +++ b/MastodonSDK/Sources/MastodonLocalization/Resources/Base.lproj/Localizable.strings @@ -138,7 +138,6 @@ Please check your internet connection."; "Common.Controls.Status.Buttons.ReblogsTitle" = "Boosts"; "Common.Controls.Status.Card.By" = "By"; "Common.Controls.Status.Card.ByAuthor" = "By %@"; -"Common.Controls.Status.Card.PublisherDate" = "%@ · %@"; "Common.Controls.Status.ContentWarning" = "Content Warning"; "Common.Controls.Status.EditHistory.OriginalPost" = "Original Post · %@"; "Common.Controls.Status.EditHistory.Title" = "Edit History"; diff --git a/MastodonSDK/Sources/MastodonUI/View/Content/StatusCardControl.swift b/MastodonSDK/Sources/MastodonUI/View/Content/StatusCardControl.swift index 7703a924a..da64d9b2c 100644 --- a/MastodonSDK/Sources/MastodonUI/View/Content/StatusCardControl.swift +++ b/MastodonSDK/Sources/MastodonUI/View/Content/StatusCardControl.swift @@ -33,7 +33,12 @@ public final class StatusCardControl: UIControl { private let highlightView = UIView() private let dividerView = UIView() private let imageView = UIImageView() + + private let publisherDateStackView: UIStackView private let publisherLabel = UILabel() + private let publisherDateSeparaturLabel = UILabel() + private let dateLabel = UILabel() + private let titleLabel = UILabel() private let descriptionLabel = UILabel() private lazy var showEmbedButton: UIButton = { @@ -90,7 +95,7 @@ public final class StatusCardControl: UIControl { mastodonLogoImageView.translatesAutoresizingMaskIntoConstraints = false byLabel = UILabel() - byLabel.text = "By" + byLabel.text = L10n.Common.Controls.Status.Card.by byLabel.numberOfLines = 1 byLabel.textColor = .secondaryLabel byLabel.font = UIFontMetrics(forTextStyle: .subheadline).scaledFont(for: .systemFont(ofSize: 15, weight: .regular)) @@ -99,9 +104,25 @@ public final class StatusCardControl: UIControl { authorLabel.numberOfLines = 1 publisherLabel.numberOfLines = 1 + publisherLabel.setContentCompressionResistancePriority(.defaultLow, for: .horizontal) publisherLabel.font = UIFontMetrics(forTextStyle: .footnote).scaledFont(for: .systemFont(ofSize: 13, weight: .regular)) publisherLabel.textColor = .secondaryLabel + publisherDateSeparaturLabel.numberOfLines = 1 + publisherDateSeparaturLabel.font = UIFontMetrics(forTextStyle: .footnote).scaledFont(for: .systemFont(ofSize: 13, weight: .regular)) + publisherDateSeparaturLabel.textColor = .secondaryLabel + publisherDateSeparaturLabel.text = "·" + + dateLabel.numberOfLines = 1 + dateLabel.setContentCompressionResistancePriority(.required, for: .horizontal) + dateLabel.font = UIFontMetrics(forTextStyle: .footnote).scaledFont(for: .systemFont(ofSize: 13, weight: .regular)) + dateLabel.textColor = .secondaryLabel + + publisherDateStackView = UIStackView(arrangedSubviews: [publisherLabel, publisherDateSeparaturLabel, dateLabel, UIView()]) + publisherDateStackView.axis = .horizontal + publisherDateStackView.alignment = .firstBaseline + publisherDateStackView.spacing = 3 + authorAccountButton = StatusCardAuthorControl() authorStackView = UIStackView(arrangedSubviews: [mastodonLogoImageView, byLabel, authorLabel, authorAccountButton, UIView()]) @@ -141,7 +162,7 @@ public final class StatusCardControl: UIControl { imageView.setContentCompressionResistancePriority(.zero, for: .horizontal) imageView.setContentCompressionResistancePriority(.zero, for: .vertical) - labelStackView.addArrangedSubview(publisherLabel) + labelStackView.addArrangedSubview(publisherDateStackView) labelStackView.addArrangedSubview(titleLabel) labelStackView.addArrangedSubview(descriptionLabel) labelStackView.layoutMargins = .init(top: 16, left: 16, bottom: 16, right: 16) @@ -200,17 +221,18 @@ public final class StatusCardControl: UIControl { } if let providerName = card.providerName { - let publisherDateText: String if let formattedPublishedDate = card.publishedAt?.abbreviatedDate { - publisherDateText = "\(providerName) · \(formattedPublishedDate)" + dateLabel.text = formattedPublishedDate + publisherDateSeparaturLabel.isHidden = false } else { - publisherDateText = providerName + dateLabel.isHidden = true + publisherDateSeparaturLabel.isHidden = true } - publisherLabel.text = publisherDateText - publisherLabel.isHidden = false + publisherLabel.text = providerName + publisherDateStackView.isHidden = false } else { - publisherLabel.isHidden = true + publisherDateStackView.isHidden = true } if let author = card.authors?.first, let account = author.account {