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 { NavigationLink {
EmojiCollectionView( EmojiCollectionView(
hoarder: hoarder, hoarder: hoarder,
items: hoarder.emojis.prefix(50).map { $0.name } items: hoarder.emojis.prefix(100).map { $0.name }
) )
} label: { } label: {
Label("", systemImage: "square.grid.2x2.fill") Label("grid view", systemImage: "square.grid.2x2.fill")
} }
Button("Refresh", systemImage: "arrow.clockwise", role: .destructive) { Button("Refresh", systemImage: "arrow.clockwise", role: .destructive) {
@@ -10,13 +10,23 @@ import UIKit
import SwiftUI import SwiftUI
class EmojiCollectionViewCell: UICollectionViewCell { class EmojiCollectionViewCell: UICollectionViewCell {
let spinner = UIActivityIndicatorView()
override init(frame: CGRect) { override init(frame: CGRect) {
super.init(frame: frame) 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.frame = frame
spinner.startAnimating() spinner.startAnimating()
self.contentView.addSubview(spinner) self.contentView.addSubview(spinner)
spinner.translatesAutoresizingMaskIntoConstraints = false spinner.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([ NSLayoutConstraint.activate([
spinner.topAnchor.constraint(equalTo: contentView.topAnchor), spinner.topAnchor.constraint(equalTo: contentView.topAnchor),
@@ -26,7 +36,12 @@ class EmojiCollectionViewCell: UICollectionViewCell {
]) ])
} }
required init?(coder: NSCoder) { override func prepareForReuse() {
fatalError("init(coder:) has not been implemented") super.prepareForReuse()
spinner.removeFromSuperview()
if spinner.superview == nil {
configure()
}
} }
} }
+9 -6
View File
@@ -18,8 +18,15 @@ class EmojiTableViewCell: UITableViewCell {
backgroundColor = .systemGroupedBackground backgroundColor = .systemGroupedBackground
contentView.backgroundColor = .clear contentView.backgroundColor = .clear
spinner.startAnimating() }
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func configureSkeleton() {
spinner.frame = frame spinner.frame = frame
spinner.startAnimating()
contentView.addSubview(spinner) contentView.addSubview(spinner)
spinner.translatesAutoresizingMaskIntoConstraints = false spinner.translatesAutoresizingMaskIntoConstraints = false
@@ -29,10 +36,7 @@ class EmojiTableViewCell: UITableViewCell {
spinner.leadingAnchor.constraint(equalTo: contentView.leadingAnchor), spinner.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),
spinner.trailingAnchor.constraint(equalTo: contentView.trailingAnchor) spinner.trailingAnchor.constraint(equalTo: contentView.trailingAnchor)
]) ])
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
} }
func configure(with hoarder: EmojiHoarder, emoji: Emoji) { func configure(with hoarder: EmojiHoarder, emoji: Emoji) {
@@ -63,8 +67,7 @@ class EmojiTableViewCell: UITableViewCell {
hostingController?.view.removeFromSuperview() hostingController?.view.removeFromSuperview()
hostingController = nil hostingController = nil
if spinner.superview == 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.