minor architectural improvements to how cells are created and reused, fixing the empty thingies if u get them off of screen and back on

This commit is contained in:
neon443 committed 2026-04-24 23:52:43 +01:00
1 parent 6ac4166283
commit 1951eccf36
3 files changed
+29 -11

No files matched your search

+2 -2
View File
@@ -115,10 +115,10 @@ struct SettingsView: View {
NavigationLink {
EmojiCollectionView(
hoarder: hoarder,
items: hoarder.emojis.prefix(50).map { $0.name }
items: hoarder.emojis.prefix(100).map { $0.name }
)
} label: {
Label("", systemImage: "square.grid.2x2.fill")
Label("grid view", systemImage: "square.grid.2x2.fill")
}
Button("Refresh", systemImage: "arrow.clockwise", role: .destructive) {
@@ -10,13 +10,23 @@ import UIKit
import SwiftUI
class EmojiCollectionViewCell: UICollectionViewCell {
let spinner = UIActivityIndicatorView()
override init(frame: CGRect) {
super.init(frame: frame)
let spinner = UIActivityIndicatorView()
configure()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func configure() {
spinner.frame = frame
spinner.startAnimating()
self.contentView.addSubview(spinner)
spinner.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
spinner.topAnchor.constraint(equalTo: contentView.topAnchor),
@@ -26,7 +36,12 @@ class EmojiCollectionViewCell: UICollectionViewCell {
])
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
override func prepareForReuse() {
super.prepareForReuse()
spinner.removeFromSuperview()
if spinner.superview == nil {
configure()
}
}
}
+9 -6
View File
@@ -18,8 +18,15 @@ class EmojiTableViewCell: UITableViewCell {
backgroundColor = .systemGroupedBackground
contentView.backgroundColor = .clear
spinner.startAnimating()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func configureSkeleton() {
spinner.frame = frame
spinner.startAnimating()
contentView.addSubview(spinner)
spinner.translatesAutoresizingMaskIntoConstraints = false
@@ -29,10 +36,7 @@ class EmojiTableViewCell: UITableViewCell {
spinner.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),
spinner.trailingAnchor.constraint(equalTo: contentView.trailingAnchor)
])
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func configure(with hoarder: EmojiHoarder, emoji: Emoji) {
@@ -63,8 +67,7 @@ class EmojiTableViewCell: UITableViewCell {
hostingController?.view.removeFromSuperview()
hostingController = nil
if spinner.superview == nil {
contentView.addSubview(spinner)
configureSkeleton()
}
spinner.startAnimating()
}
}
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.