Compare commits

...

2 Commits

Author SHA1 Message Date
Shadowfacts 176eb7c011 Undo overzealous Xcode rename 2024-07-21 18:41:03 -07:00
Shadowfacts da9ca78a8b Update card view less often
Speculative fix for #314
2024-07-21 18:40:58 -07:00
3 changed files with 40 additions and 14 deletions

View File

@ -22,7 +22,7 @@ class SuggestedProfileCardCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var headerImageView: CachedImageView!
@IBOutlet weak var avatarContainerView: UIView!
@IBOutlet weak var avatarImageView: CachedImageView!
@IBOutlet weak var displayAndUserNameLabel: AccountDisplayNameLabel!
@IBOutlet weak var displayNameLabel: AccountDisplayNameLabel!
@IBOutlet weak var usernameLabel: UILabel!
@IBOutlet weak var noteTextView: StatusContentTextView!
@IBOutlet weak var suggestionSourceButton: UIButton!
@ -49,8 +49,8 @@ class SuggestedProfileCardCollectionViewCell: UICollectionViewCell {
avatarImageView.layer.masksToBounds = true
avatarImageView.layer.cornerCurve = .continuous
displayAndUserNameLabel.font = UIFontMetrics(forTextStyle: .title1).scaledFont(for: .systemFont(ofSize: 24, weight: .semibold))
displayAndUserNameLabel.adjustsFontForContentSizeCategory = true
displayNameLabel.font = UIFontMetrics(forTextStyle: .title1).scaledFont(for: .systemFont(ofSize: 24, weight: .semibold))
displayNameLabel.adjustsFontForContentSizeCategory = true
usernameLabel.font = UIFontMetrics.default.scaledFont(for: .systemFont(ofSize: 15, weight: .light))
usernameLabel.adjustsFontForContentSizeCategory = true
@ -96,7 +96,7 @@ class SuggestedProfileCardCollectionViewCell: UICollectionViewCell {
private func updateUIForPreferences(account: AccountMO) {
avatarContainerView.layer.cornerRadius = Preferences.shared.avatarStyle.cornerRadius(for: avatarContainerView)
avatarImageView.layer.cornerRadius = Preferences.shared.avatarStyle.cornerRadius(for: avatarImageView)
displayAndUserNameLabel.updateForAccountDisplayName(account: account)
displayNameLabel.updateForAccountDisplayName(account: account)
}
// Unneeded on visionOS since there is no light/dark mode

View File

@ -135,12 +135,11 @@ private struct MockStatusCardView: UIViewRepresentable {
func makeUIView(context: Context) -> StatusCardView {
let view = StatusCardView()
view.isUserInteractionEnabled = false
let card = Card(
let card = StatusCardView.CardData(
url: WebURL("https://vaccor.space/tusker")!,
title: "Tusker",
description: "Tusker is an iOS app for Mastodon",
image: WebURL("https://vaccor.space/tusker/img/icon.png")!,
kind: .link
title: "Tusker",
description: "Tusker is an iOS app for Mastodon"
)
view.updateUI(card: card, sensitive: false)
return view

View File

@ -9,6 +9,7 @@
import UIKit
import Pachyderm
import SafariServices
import WebURL
import WebURLFoundationExtras
import HTMLStreamer
@ -18,7 +19,7 @@ class StatusCardView: UIView {
weak var actionProvider: MenuActionProvider?
private var statusID: String?
private(set) var card: Card?
private(set) var card: CardData?
private static let activeBackgroundColor = UIColor.secondarySystemFill
private static let inactiveBackgroundColor = UIColor.secondarySystemBackground
@ -163,20 +164,22 @@ class StatusCardView: UIView {
}
func updateUI(status: StatusMO) {
guard status.id != statusID else {
let newData = status.card.map { CardData(card: $0) }
guard self.card != newData else {
return
}
self.card = status.card
self.card = newData
self.statusID = status.id
guard let card = status.card else {
guard let newData else {
return
}
updateUI(card: card, sensitive: status.sensitive)
updateUI(card: newData, sensitive: status.sensitive)
}
func updateUI(card: Card, sensitive: Bool) {
// This method is internal for use by MockStatusView
func updateUI(card: CardData, sensitive: Bool) {
if let image = card.image {
if sensitive {
if let blurhash = card.blurhash {
@ -244,6 +247,30 @@ class StatusCardView: UIView {
setNeedsDisplay()
}
struct CardData: Equatable {
let url: WebURL
let image: WebURL?
let title: String
let description: String
let blurhash: String?
init(card: Card) {
self.url = card.url
self.image = card.image
self.title = card.title
self.description = card.description
self.blurhash = card.blurhash
}
init(url: WebURL, image: WebURL? = nil, title: String, description: String, blurhash: String? = nil) {
self.url = url
self.image = image
self.title = title
self.description = description
self.blurhash = blurhash
}
}
}
extension StatusCardView: UIContextMenuInteractionDelegate {