From 53d8c1ee5e0a6bb6484eeafe40de7f335e449ae6 Mon Sep 17 00:00:00 2001 From: Nihaal Sharma <69979447+neon443@users.noreply.github.com> Date: Fri, 1 May 2026 15:05:27 +0100 Subject: [PATCH] trying to redo sizeforitemat, figuring out better tableview reloads --- StickerSlack/Emoji/EmojiHoarder.swift | 2 ++ StickerSlack/SwiftUI/BrowseView.swift | 1 - .../UIKit/CollectionView/EmojiCollectionView.swift | 7 +++++++ StickerSlack/UIKit/TableView/EmojiTableView.swift | 13 ++++++++++++- 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/StickerSlack/Emoji/EmojiHoarder.swift b/StickerSlack/Emoji/EmojiHoarder.swift index 834d79a..d2a71a7 100644 --- a/StickerSlack/Emoji/EmojiHoarder.swift +++ b/StickerSlack/Emoji/EmojiHoarder.swift @@ -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) diff --git a/StickerSlack/SwiftUI/BrowseView.swift b/StickerSlack/SwiftUI/BrowseView.swift index cc06a9c..d54970b 100644 --- a/StickerSlack/SwiftUI/BrowseView.swift +++ b/StickerSlack/SwiftUI/BrowseView.swift @@ -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 { diff --git a/StickerSlack/UIKit/CollectionView/EmojiCollectionView.swift b/StickerSlack/UIKit/CollectionView/EmojiCollectionView.swift index 4e22bd1..df78a23 100644 --- a/StickerSlack/UIKit/CollectionView/EmojiCollectionView.swift +++ b/StickerSlack/UIKit/CollectionView/EmojiCollectionView.swift @@ -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) } diff --git a/StickerSlack/UIKit/TableView/EmojiTableView.swift b/StickerSlack/UIKit/TableView/EmojiTableView.swift index ee5b0e1..9440892 100644 --- a/StickerSlack/UIKit/TableView/EmojiTableView.swift +++ b/StickerSlack/UIKit/TableView/EmojiTableView.swift @@ -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 {