diff --git a/Tusker/Screens/Preferences/Appearance/MockStatusView.swift b/Tusker/Screens/Preferences/Appearance/MockStatusView.swift index 5c313ae1c4..5cbd46e25d 100644 --- a/Tusker/Screens/Preferences/Appearance/MockStatusView.swift +++ b/Tusker/Screens/Preferences/Appearance/MockStatusView.swift @@ -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 diff --git a/Tusker/Views/Status/StatusCardView.swift b/Tusker/Views/Status/StatusCardView.swift index b8f7d6bba0..a8feb6bd7e 100644 --- a/Tusker/Views/Status/StatusCardView.swift +++ b/Tusker/Views/Status/StatusCardView.swift @@ -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 { @@ -243,6 +246,30 @@ class StatusCardView: UIView { hStack.backgroundColor = StatusCardView.inactiveBackgroundColor 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 + } + } }