fix: date meta may be trunked in thread scene issue. resolve #285

This commit is contained in:
CMK 2021-08-16 13:53:23 +08:00
parent 7667d9ad3f
commit 143c6a0a99
2 changed files with 28 additions and 15 deletions

View File

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

View File

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