Update card view less often

Speculative fix for #314
This commit is contained in:
Shadowfacts 2024-07-21 18:40:58 -07:00
parent b470ee6401
commit da9ca78a8b
2 changed files with 36 additions and 10 deletions

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