forked from shadowfacts/Tusker
Avoid unnecessarily recreating avatar views in notifications cells
This commit is contained in:
parent
bf1ed57180
commit
a2fe0dfb78
|
@ -139,20 +139,26 @@ class ActionNotificationGroupCollectionViewCell: UICollectionViewListCell {
|
||||||
mastodonController.persistentContainer.account(for: $0.account.id)
|
mastodonController.persistentContainer.account(for: $0.account.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
avatarStack.arrangedSubviews.forEach { $0.removeFromSuperview() }
|
let visibleAvatars = Array(people.lazy.compactMap(\.avatar).prefix(10))
|
||||||
for avatarURL in people.lazy.compactMap(\.avatar).prefix(10) {
|
for (index, avatarURL) in visibleAvatars.enumerated() {
|
||||||
let imageView = CachedImageView(cache: .avatars)
|
let imageView: CachedImageView
|
||||||
imageView.contentMode = .scaleAspectFill
|
if index < avatarStack.arrangedSubviews.count {
|
||||||
imageView.layer.masksToBounds = true
|
imageView = avatarStack.arrangedSubviews[index] as! CachedImageView
|
||||||
imageView.layer.cornerRadius = Preferences.shared.avatarStyle.cornerRadiusFraction * 30
|
} else {
|
||||||
imageView.layer.cornerCurve = .continuous
|
imageView = CachedImageView(cache: .avatars)
|
||||||
avatarStack.addArrangedSubview(imageView)
|
imageView.contentMode = .scaleAspectFill
|
||||||
|
imageView.layer.masksToBounds = true
|
||||||
|
imageView.layer.cornerRadius = Preferences.shared.avatarStyle.cornerRadiusFraction * 30
|
||||||
|
imageView.layer.cornerCurve = .continuous
|
||||||
|
avatarStack.addArrangedSubview(imageView)
|
||||||
|
imageView.widthAnchor.constraint(equalTo: imageView.heightAnchor).isActive = true
|
||||||
|
}
|
||||||
imageView.update(for: avatarURL)
|
imageView.update(for: avatarURL)
|
||||||
}
|
}
|
||||||
NSLayoutConstraint.activate(avatarStack.arrangedSubviews.map {
|
for imageView in avatarStack.arrangedSubviews.dropFirst(visibleAvatars.count) {
|
||||||
$0.widthAnchor.constraint(equalTo: $0.heightAnchor)
|
avatarStack.removeArrangedSubview(imageView)
|
||||||
})
|
}
|
||||||
|
|
||||||
actionLabel.setEmojis(pairs: people.map { ($0.displayOrUserName, $0.emojis) }, identifier: group.id)
|
actionLabel.setEmojis(pairs: people.map { ($0.displayOrUserName, $0.emojis) }, identifier: group.id)
|
||||||
|
|
||||||
// todo: use htmlconverter
|
// todo: use htmlconverter
|
||||||
|
|
|
@ -116,19 +116,25 @@ class FollowNotificationGroupCollectionViewCell: UICollectionViewListCell {
|
||||||
}, identifier: group.id)
|
}, identifier: group.id)
|
||||||
updateTimestamp()
|
updateTimestamp()
|
||||||
|
|
||||||
avatarStack.arrangedSubviews.forEach { $0.removeFromSuperview() }
|
let visibleAvatars = Array(people.lazy.compactMap(\.avatar).prefix(10))
|
||||||
for avatarURL in people.lazy.compactMap(\.avatar).prefix(10) {
|
for (index, avatarURL) in visibleAvatars.enumerated() {
|
||||||
let imageView = CachedImageView(cache: .avatars)
|
let imageView: CachedImageView
|
||||||
imageView.contentMode = .scaleAspectFill
|
if index < avatarStack.arrangedSubviews.count {
|
||||||
imageView.layer.masksToBounds = true
|
imageView = avatarStack.arrangedSubviews[index] as! CachedImageView
|
||||||
imageView.layer.cornerRadius = Preferences.shared.avatarStyle.cornerRadiusFraction * 30
|
} else {
|
||||||
imageView.layer.cornerCurve = .continuous
|
imageView = CachedImageView(cache: .avatars)
|
||||||
|
imageView.contentMode = .scaleAspectFill
|
||||||
|
imageView.layer.masksToBounds = true
|
||||||
|
imageView.layer.cornerRadius = Preferences.shared.avatarStyle.cornerRadiusFraction * 30
|
||||||
|
imageView.layer.cornerCurve = .continuous
|
||||||
|
avatarStack.addArrangedSubview(imageView)
|
||||||
|
imageView.widthAnchor.constraint(equalTo: imageView.heightAnchor).isActive = true
|
||||||
|
}
|
||||||
imageView.update(for: avatarURL)
|
imageView.update(for: avatarURL)
|
||||||
avatarStack.addArrangedSubview(imageView)
|
|
||||||
}
|
}
|
||||||
NSLayoutConstraint.activate(avatarStack.arrangedSubviews.map {
|
for imageView in avatarStack.arrangedSubviews.dropFirst(visibleAvatars.count) {
|
||||||
$0.widthAnchor.constraint(equalTo: $0.heightAnchor)
|
avatarStack.removeArrangedSubview(imageView)
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func updateActionLabel(names: [NSAttributedString]) -> NSAttributedString {
|
private func updateActionLabel(names: [NSAttributedString]) -> NSAttributedString {
|
||||||
|
|
Loading…
Reference in New Issue