trying to redo sizeforitemat, figuring out better tableview reloads

This commit is contained in:
Nihaal Sharma committed 2026-05-01 15:05:27 +01:00
1 parent 646725dc11
commit 53d8c1ee5e
4 files changed
+21 -2

No files matched your search

+2
View File
@@ -105,6 +105,7 @@ class EmojiHoarder: BaseHoarder {
}
await MainActor.run {
downloadedStickers = []
downloadedStickersArr = []
}
}
@@ -209,6 +210,7 @@ class EmojiHoarder: BaseHoarder {
await super.download(emoji: emoji, skipStoreIndex: skipStoreIndex)
await MainActor.run {
emojis.insert(.test, at: emojis.count-2)
if !skipStoreIndex {
let _ = withAnimation(.snappy) {
self.downloadedStickers.insert(emoji.name)
-1
View File
@@ -30,7 +30,6 @@ struct BrowseView: View {
items: emojiHoarder.emojis.map { $0.name }
)
.padding(.bottom, 10)
.id(emojiHoarder.emojis)
case .giphyGifs:
Button("download all") {
for gif in gifHoarder.trendingGifs {
@@ -196,6 +196,13 @@ struct EmojiCollectionView: UIViewRepresentable {
}
}
let font = UIFont.preferredFont(forTextStyle: .caption1)
let rect = (emojiName as NSString).boundingRect(
with: CGSize(width: itemWidth, height: .greatestFiniteMagnitude),
options: [.usesLineFragmentOrigin, .usesFontLeading],
attributes: [.font: font],
context: nil
)
return CGSize(width: itemWidth, height: itemWidth+labelHeight+4)
}
@@ -23,8 +23,19 @@ struct EmojiTableView: UIViewRepresentable {
func updateUIView(_ uiView: UITableView, context: Context) {
context.coordinator.hoarder = hoarder
let itemsBefore = context.coordinator.items
let itemsAfter = items
context.coordinator.items = items
uiView.reloadData()
if itemsAfter.count > itemsBefore.count {
var indexPaths: [IndexPath] = []
for i in (itemsBefore.count-1)...(itemsAfter.count-1) {
indexPaths.append(IndexPath(row: i, section: 0))
}
uiView.insertRows(at: indexPaths, with: .fade)
} else {
uiView.reloadData()
}
}
func makeCoordinator() -> Coordinator {
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.