From 143c6a0a99e0be4776639dbde0a3393ef027dcdd Mon Sep 17 00:00:00 2001 From: CMK Date: Mon, 16 Aug 2021 13:53:23 +0800 Subject: [PATCH] fix: date meta may be trunked in thread scene issue. resolve #285 --- .../Section/Status/StatusSection.swift | 25 +++++++++++++------ .../Share/View/Content/ThreadMetaView.swift | 18 +++++++------ 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/Mastodon/Diffiable/Section/Status/StatusSection.swift b/Mastodon/Diffiable/Section/Status/StatusSection.swift index 6ec997845..f16311b6a 100644 --- a/Mastodon/Diffiable/Section/Status/StatusSection.swift +++ b/Mastodon/Diffiable/Section/Status/StatusSection.swift @@ -603,24 +603,33 @@ extension StatusSection { status: Status ) { cell.selectionStyle = .none - cell.threadMetaView.dateLabel.text = { - let formatter = DateFormatter() - formatter.dateStyle = .medium - formatter.timeStyle = .short - return formatter.string(from: status.createdAt) - }() - cell.threadMetaView.dateLabel.accessibilityLabel = DateFormatter.localizedString(from: status.createdAt, dateStyle: .medium, timeStyle: .short) + + // set reblog count let reblogCountTitle: String = { let count = status.reblogsCount.intValue return L10n.Plural.Count.reblog(count) }() cell.threadMetaView.reblogButton.setTitle(reblogCountTitle, for: .normal) - + // set favorite count let favoriteCountTitle: String = { let count = status.favouritesCount.intValue return L10n.Plural.Count.favorite(count) }() cell.threadMetaView.favoriteButton.setTitle(favoriteCountTitle, for: .normal) + // set date + cell.threadMetaView.dateLabel.text = { + let formatter = DateFormatter() + // make adaptive UI + if UIView.isZoomedMode || (reblogCountTitle.count + favoriteCountTitle.count > 20) { + formatter.dateStyle = .short + formatter.timeStyle = .short + } else { + formatter.dateStyle = .medium + formatter.timeStyle = .short + } + return formatter.string(from: status.createdAt) + }() + cell.threadMetaView.dateLabel.accessibilityLabel = DateFormatter.localizedString(from: status.createdAt, dateStyle: .medium, timeStyle: .short) cell.threadMetaView.isHidden = false } diff --git a/Mastodon/Scene/Share/View/Content/ThreadMetaView.swift b/Mastodon/Scene/Share/View/Content/ThreadMetaView.swift index d6f1b01a9..4bda525ae 100644 --- a/Mastodon/Scene/Share/View/Content/ThreadMetaView.swift +++ b/Mastodon/Scene/Share/View/Content/ThreadMetaView.swift @@ -15,6 +15,7 @@ final class ThreadMetaView: UIView { label.text = "Date" label.adjustsFontSizeToFitWidth = true label.minimumScaleFactor = 0.5 + label.numberOfLines = 2 return label }() @@ -39,7 +40,7 @@ final class ThreadMetaView: UIView { let containerStackView: UIStackView = { let stackView = UIStackView() stackView.axis = .horizontal - stackView.spacing = 20 + stackView.spacing = 4 return stackView }() let actionButtonStackView = UIStackView() @@ -77,9 +78,9 @@ extension ThreadMetaView { actionButtonStackView.addArrangedSubview(favoriteButton) dateLabel.setContentHuggingPriority(.defaultLow, for: .horizontal) - reblogButton.titleLabel?.setContentHuggingPriority(.required - 2, for: .horizontal) - favoriteButton.titleLabel?.setContentHuggingPriority(.required - 1, for: .horizontal) + reblogButton.setContentHuggingPriority(.required - 2, for: .horizontal) reblogButton.setContentCompressionResistancePriority(.required - 2, for: .horizontal) + favoriteButton.setContentHuggingPriority(.required - 1, for: .horizontal) favoriteButton.setContentCompressionResistancePriority(.required - 1, for: .horizontal) updateContainerLayout() @@ -98,12 +99,15 @@ extension ThreadMetaView { private func updateContainerLayout() { if traitCollection.preferredContentSizeCategory < .accessibilityMedium { containerStackView.axis = .horizontal - containerStackView.spacing = 20 - dateLabel.numberOfLines = 1 + + if bounds.size.width < 400 || UIView.isZoomedMode { + actionButtonStackView.spacing = 10 + } else { + actionButtonStackView.spacing = 20 + } } else { containerStackView.axis = .vertical - containerStackView.spacing = 4 - dateLabel.numberOfLines = 0 + actionButtonStackView.spacing = 20 } }