diff --git a/MastodonSDK/Sources/CoreDataStack/Entity/Mastodon/Card.swift b/MastodonSDK/Sources/CoreDataStack/Entity/Mastodon/Card.swift index 64f5e2120b..f74bcc0768 100644 --- a/MastodonSDK/Sources/CoreDataStack/Entity/Mastodon/Card.swift +++ b/MastodonSDK/Sources/CoreDataStack/Entity/Mastodon/Card.swift @@ -56,6 +56,17 @@ public final class Card: NSManagedObject { @NSManaged public private(set) var status: Status } +extension Card { + public var websiteName: String? { + if let authorName, !authorName.isEmpty { + return authorName + } else if let host = url?.host { + return host + } + return nil + } +} + extension Card { @discardableResult diff --git a/MastodonSDK/Sources/MastodonUI/View/Content/StatusCardControl.swift b/MastodonSDK/Sources/MastodonUI/View/Content/StatusCardControl.swift index 90af468b66..3e930d2379 100644 --- a/MastodonSDK/Sources/MastodonUI/View/Content/StatusCardControl.swift +++ b/MastodonSDK/Sources/MastodonUI/View/Content/StatusCardControl.swift @@ -31,7 +31,8 @@ public final class StatusCardControl: UIControl { private let dividerView = UIView() private let imageView = UIImageView() private let titleLabel = UILabel() - private let linkLabel = UILabel() + private let descriptionLabel = UILabel() + private let siteNameLabel = UILabel() private lazy var showEmbedButton: UIButton = { var configuration = UIButton.Configuration.gray() configuration.background.visualEffect = UIBlurEffect(style: .systemUltraThinMaterial) @@ -85,11 +86,20 @@ public final class StatusCardControl: UIControl { titleLabel.numberOfLines = 2 titleLabel.textColor = Asset.Colors.Label.primary.color - titleLabel.font = .preferredFont(forTextStyle: .body) - - linkLabel.numberOfLines = 1 - linkLabel.textColor = Asset.Colors.Label.secondary.color - linkLabel.font = .preferredFont(forTextStyle: .subheadline) + let descriptor = UIFont.preferredFont(forTextStyle: .body) + .fontDescriptor + .addingAttributes([.traits: [UIFontDescriptor.TraitKey.weight: UIFont.Weight.medium]]) + titleLabel.font = UIFontMetrics(forTextStyle: .body) + .scaledFont(for: UIFont(descriptor: descriptor, size: descriptor.pointSize)) + titleLabel.adjustsFontForContentSizeCategory = false + + descriptionLabel.numberOfLines = 2 + descriptionLabel.textColor = Asset.Colors.Label.primary.color + descriptionLabel.font = .preferredFont(forTextStyle: .caption1) + + siteNameLabel.numberOfLines = 1 + siteNameLabel.textColor = Asset.Colors.Label.secondary.color + siteNameLabel.font = .preferredFont(forTextStyle: .subheadline) imageView.tintColor = Asset.Colors.Label.secondary.color imageView.contentMode = .scaleAspectFill @@ -100,7 +110,8 @@ public final class StatusCardControl: UIControl { imageView.setContentCompressionResistancePriority(.zero, for: .vertical) labelStackView.addArrangedSubview(titleLabel) - labelStackView.addArrangedSubview(linkLabel) + labelStackView.addArrangedSubview(descriptionLabel) + labelStackView.addArrangedSubview(siteNameLabel) labelStackView.layoutMargins = .init(top: 10, left: 10, bottom: 10, right: 10) labelStackView.isLayoutMarginsRelativeArrangement = true labelStackView.axis = .vertical @@ -139,14 +150,15 @@ public final class StatusCardControl: UIControl { public func configure(card: Card) { let title = card.title.trimmingCharacters(in: .whitespacesAndNewlines) - if let host = card.url?.host { - accessibilityLabel = "\(title) \(host)" + if let websiteName = card.websiteName { + accessibilityLabel = "\(title) \(websiteName)" } else { accessibilityLabel = title } titleLabel.text = title - linkLabel.text = card.url?.host + descriptionLabel.text = card.desc.trimmingCharacters(in: .whitespacesAndNewlines) + siteNameLabel.text = card.websiteName imageView.contentMode = .center imageView.sd_setImage( @@ -208,6 +220,7 @@ public final class StatusCardControl: UIControl { .constraint(lessThanOrEqualToConstant: 400), ] dividerConstraint = dividerView.heightAnchor.constraint(equalToConstant: pixelSize).activate() + descriptionLabel.isHidden = false case .compact: containerStackView.alignment = .center containerStackView.axis = .horizontal @@ -219,6 +232,7 @@ public final class StatusCardControl: UIControl { dividerView.heightAnchor.constraint(equalTo: containerStackView.heightAnchor), ] dividerConstraint = dividerView.widthAnchor.constraint(equalToConstant: pixelSize).activate() + descriptionLabel.isHidden = true } NSLayoutConstraint.activate(layoutConstraints)